Artifacts Associated With Ticket 69634d51fb
Ticket change [28254a00d7] (rid 182782) by dgp on 2020-04-29 15:40:29:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The valid range of unicode extends from U+0000 to U+10FFFF. Routines that accept an int argument meant to represent a unicode code point have to decide how to handle a value of 0x110000 and above. One example is the routine Tcl_UniCharIsGraph(), but there are many. Tcl 8.5 routes the handling to the inner workings of GetUniCharInfo(), which masks away unacceptable high bits. This indicates that Tcl_UniCharIsGraph( 0x200041) will return 1 (masked to make \x41 "A") while Tcl_UniCharIsGraph( 0x200020) will return 0 (masked to make \x20 " "). Since these are both invalid inputs, I think it would make more sense to have them produce the same results. In many situations, invalid inputs are transformed into U+FFFD, the replacement character. That makes more sense to me. Moving forward through versions and variants, there are different handlings in place. In 8.7, there is masking of the output of routines like Tcl_UniCharToLower, when the constraint would seem to be more useful on what comes in instead of what goes out.
- is_private initialized to: "0"
- login: "dgp"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "dgp"
- subsystem initialized to: "44. UTF-8 Strings"
- title initialized to: "handling out of range UCS4 values"
- type initialized to: "Bug"
Ticket change [5b4e108771] (rid 182783) by dgp on 2020-04-29 15:42:13:
- icomment:
Note that masking away high bits doesn't help at all with an input value like 0x110000 , which is out of range but keeps all bits after masking. We'd at least be worried that such values lead to invalid lookup table accesses.
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [8b920ae5ee] (rid 182784) by jan.nijtmans on 2020-04-29 16:17:05:
- icomment:
Whenever Tcl accept chars > \xFFFF, there's a UNICODE_OUT_OF_RANGE macro which checks for possible overflow. So there's no possibility for invalid lookup table access. For Tcl 8.5/8.6, the input 'integer' is masked using 16 bits. This is logical, since those functions are only defined accepting an Tcl_UniChar. In Tcl 8.7 that changes. For reasons of extensability, the input values are now masked using 21 bits. This allows bits 22 up to 31 to used for other purposes. For example Tcl_UniCharToUpper() could become locale-dependant: Uppercase 'i' in turkish is "İ", not "I". The lowercase form of "I" is "ı", not "i". So flags could be used in Tcl_UniCharToUpper()/Tcl_UniCharToLower() to indicate whether we want the Turkish variant or the rest-of-the-world variant. So, I don't think there's a bug here.
- login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [0270590773] (rid 182804) by jan.nijtmans on 2020-04-29 20:58:23:
- assignee changed to: "dgp"
- icomment:
I think the range checking is fixed now in Tcl 8.5 and 8.6, for builds with sizeof(Tcl_UniChar) == 4. Backported those bits and pieces from 8.7. So, if there still are bugs here (I don't think so), that means they still are not fixed in 8.7 either. That's the reason for the differences in branches: Various fixes where never backported to 8.6 and 8.5. Good luck!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Pending"
Ticket change [7e4e593bfd] (rid 182857) by dgp on 2020-04-30 14:32:12:
- icomment:
The masking of output values from routines like Tcl_UniCharToUpper https://core.tcl-lang.org/tcl/artifact/16c3f0784c45ed55?ln=1277 seems unnecessary to me. Harmless, but why bother? Can we not count on our processing to produce results already valid and already clear of any of those extension bits?
- login: "dgp"
- mimetype: "text/plain"
- icomment:
Ticket change [832431af7c] (rid 182861) by jan.nijtmans on 2020-04-30 15:03:33:
- icomment:
> Can we not count on our processing to produce results already valid and already clear of any of those extension bits? No we cannot since the UNICODE_OUT_OF_RANGE(), GetUniCharInfo(), GetCaseType() and GetDelta() all do their own masking with 0x1FFFFF already. If we use the additional bits as flags - in the future - then we don't want to see our flags back in the output. That's why we need to mask them away ourselves, the macro's don't do it. So - please - leave it as-is for now. I'll write a TIP how to handle locale-dependant Tcl_UniCharToUpper() (for e.g. Turkish, I have some ideas on that ...), but it's not high prio now so it might take a while. Thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [ff2427a1f0] (rid 258137) by serhiy.storchaka on 2026-10-15 11:29:07:
- icomment: "Closing: fixed, see above."
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"
Ticket change [deefd1a105] (rid 259938) by serhiy.storchaka on 2026-10-22 17:19:26:
- closedate changed to: "2461328.978555405"
- closer changed to: "serhiy.storchaka"
- login: "serhiy.storchaka"