Tcl Source Code

View Ticket
Login
Ticket UUID: 67fcef9acaf767003180ee05b8a35ef8ea6ae049
Title: Possible regex ranges integer overflow
Type: Bug Created on: 2016-02-16 09:56:13
Submitter: yarda81 Assigned to: nobody
Subsystem: 43. Regexp Severity: Minor
Priority: 5 Medium Last modified: 2026-10-22 17:19:24
Status: Closed Closed by: serhiy.storchaka
Resolution: Invalid Closed on: 2026-10-11 11:04:57
Version: tcl-8.6.4
Description:
Just opening the case in tcl upstream, to be aware of the problem:

https://github.com/SWI-Prolog/packages-xpce/issues/2

The chr type is 16bit, hence the maximum range size is limited to 2^16, which is not sufficient to trigger the overflow. Note that TCL can be built with 32bit chr type depending on the value of TCL_UTF_MAX macro. The default value is 3, which implies the use of 16bit chr. Other valid value is 6, but that is considered experimental upstream and not recommended.
User Comments:
serhiy.storchaka added on 2026-10-11 11:04:57:

Not reproducible in 8.6, 9.0 or 9.1. Regexp escapes are capped at U+10FFFF (lexdigits() in regc_lex.c), CHR_MAX is 0x10FFFF in 9.x, and range() uses int, so neither the loop nor the allocation size can overflow. In 8.6, chr is 16-bit by default, and the escape cap also applies with TCL_UTF_MAX > 4. The full case-insensitive range [\U00000000-\U0010ffff] compiles in milliseconds.