|
2026-10-22
| ||
| 17:19 | • Ticket [69634d51fb] handling out of range UCS4 values status still Closed wi... artifact: deefd1a105 user: serhiy.storchaka | |
|
2026-10-15
| ||
| 11:29 | • Closed ticket [69634d51fb]. artifact: ff2427a1f0 user: serhiy.storchaka | |
|
2020-04-30
| ||
| 15:03 | • Ticket [69634d51fb]: 3 changes artifact: 832431af7c user: jan.nijtmans | |
| 14:32 | • Ticket [69634d51fb]: 3 changes artifact: 7e4e593bfd user: dgp | |
|
2020-04-29
| ||
| 20:58 | • Pending ticket [69634d51fb]. artifact: 0270590773 user: jan.nijtmans | |
| 20:44 | Backport many UNICODE_OUT_OF_RANGE() calls. This should fix [69634d51fb74551b] for Tcl 8.5 (with TCL... check-in: fe05235530 user: jan.nijtmans tags: core-8-5-branch | |
| 19:00 | Add UNICODE_OUT_OF_RANGE() calls to UCS4ToTitle() and friends. Backported from 8.7. This fixes [6963... check-in: 8daf5a10dd user: jan.nijtmans tags: core-8-6-branch | |
| 16:17 | • Ticket [69634d51fb] handling out of range UCS4 values status still Open with... artifact: 8b920ae5ee user: jan.nijtmans | |
| 15:42 | • Ticket [69634d51fb]: 3 changes artifact: 5b4e108771 user: dgp | |
| 15:40 | • New ticket [69634d51fb]. artifact: 28254a00d7 user: dgp | |
handling out of range UCS4 values
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.
8daf5a10ddAdd UNICODE_OUT_OF_RANGE() calls to UCS4ToTitle() and friends. Backported from 8.7. This fixes [69634d51fb]: handling out of range UCS4 values (at least, it's fixed in 8.6 now the same way as it's fixed in 8.7). check-in2020-04-29 19:00:10
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.
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.
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!
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?
> 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!
Closing: fixed, see above.