Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2023-04-22
08:05 • New ticket [203792a48c] Avoid signed integer overflow in Utf32ToUtfProc(). artifact: 48bb1e2e08 user: chrstphrchvz
2023-03-22
12:25
Merge trunk: Final part of [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. Problem was in tes... check-in: f763b2396e user: pooryorick tags: unchained
2023-02-16
21:31 • Closed ticket [10c2c17c32]: UTF-LE32 encoder mapping of surrogates plus 7 ot... artifact: e1db249ccd user: jan.nijtmans
21:29
Final part of [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. Problem was in testcase, not in ... check-in: fc029613d5 user: jan.nijtmans tags: trunk, main
2023-02-15
07:30 • Ticket [10c2c17c32] UTF-LE32 encoder mapping of surrogates status still Open... artifact: bcd3cf0427 user: jan.nijtmans
07:21
Ticket [10c2c17c32] follow-up. One output char too much with -failindex. check-in: 6349e0c2e1 user: jan.nijtmans tags: core-8-branch
05:38 • Ticket [10c2c17c32] UTF-LE32 encoder mapping of surrogates status still Open... artifact: b446e51830 user: apnadkarni
2023-02-13
10:14 • Open ticket [10c2c17c32]. artifact: 12b9a533fe user: jan.nijtmans
08:40 • Closed ticket [10c2c17c32]. artifact: 72f8cf14bf user: jan.nijtmans
08:39
Fix for [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. With testcases (both for utf-32 and ut... check-in: 26aadbbd1f user: jan.nijtmans tags: core-8-branch
2023-02-09
07:57 • Ticket [10c2c17c32] UTF-LE32 encoder mapping of surrogates status still Open... artifact: 3624f5267d user: jan.nijtmans
2023-02-08
15:38 • Ticket [10c2c17c32]: 3 changes artifact: 0642977d2a user: apnadkarni
2023-02-07
15:02 • Ticket [10c2c17c32]: 3 changes artifact: 6cdb9ac9d5 user: jan.nijtmans
07:38 • Ticket [10c2c17c32]: 3 changes artifact: 43348994a9 user: apnadkarni
2023-02-06
22:43
Proposed fix for [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. TODO: testcase check-in: 0bb13aadb6 user: jan.nijtmans tags: bug-10c2c17c32
21:18 • Ticket [10c2c17c32] UTF-LE32 encoder mapping of surrogates status still Open... artifact: f264613885 user: jan.nijtmans
17:02 • Ticket [10c2c17c32]: 3 changes artifact: 9d8934b42d user: apnadkarni
17:01 • New ticket [10c2c17c32]. artifact: 74030b1761 user: apnadkarni

UTF-LE32 encoder mapping of surrogates

Closed / Fixed10c2c17c32ab68e6619f37994b09bbbd06462cd1Created 4 years agoUpdated 4 years ago
Descriptionmarkdown2023-02-06 17:01:49

While beefing up test cases for encoders, the following seems suspect to me.

% proc codepoints {s} {join [lmap c [split $s ""] {
    string cat U+ [format %.8X [scan $c %c]]}]
}
% codepoints [encoding convertfrom utf-32le \x41\x00\x00\x00\x00\xD8\x00\x00\x42\x00\x00\x00]
U+00000041 U+000000F0 U+00000042

Where does the U+000000F0 come from? It seems strange that 0x0000D800 gets mapped to that value. Am I missing something?

Tcl9 seems fine (maps to U+D800)

Referenced by6
  • 48bb1e2e08New ticket [203792a48c] Avoid signed integer overflow in Utf32ToUtfProc(). ticket2023-04-22 08:05:33
  • f763b2396eMerge trunk: Final part of [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. Problem was in testcase, not in actual code. check-in2023-03-22 12:25:33
  • fc029613d5Final part of [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. Problem was in testcase, not in actual code check-in2023-02-16 21:29:07
  • 6349e0c2e1Ticket [10c2c17c32] follow-up. One output char too much with -failindex. check-in2023-02-15 07:21:55
  • 26aadbbd1fFix for [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. With testcases (both for utf-32 and utf-16, which had the same bug) check-in2023-02-13 08:39:29
  • 0bb13aadb6Proposed fix for [10c2c17c32]: UTF-LE32 encoder mapping of surrogates. TODO: testcase check-in2023-02-06 22:43:30
apnadkarni Ticket [10c2c17c32]: 3 changes [History diff]2023-02-06 17:02:15
jan.nijtmanswiki2023-02-06 21:18:25

This happens because of the combining behavior of Tcl_UniCharToUtf(), which Tcl 9.0 doesn't do any more by default. Easy to fix. Will do.

You will realize that this is invalid UTF-32. When Tcl_UniCharToUtf() receives an upper surrogate, it will output the first byte of the 4-byte UTF-8 encoding (which is 0xF0, in this case). Feeding Tcl_UniCharToUtf() a lower surrogate will complete the remaining 3 bytes. In case of UTF-32, this combining should not be done, but since Tcl_UniCharToUtf() is used for UTF-16 too, that's where the problem comes from. As you already found out, in Tcl 9.0 this is corrected.

apnadkarniplain2023-02-07 07:38:49
Yes, I know it is invalid UTF-32. I'm adding tests for handling of invalid byte sequences under different profiles. If errors are not raised, the conversion should be consistent which is what I was checking.
jan.nijtmanswiki2023-02-07 15:02:10

Proposed fix [here]

apnadkarniplain2023-02-08 15:38:29
With the proposed fix, all current tests pass in my apn-encoding-profile branch. Just FYI
jan.nijtmanswiki2023-02-09 07:57:22

The bug-fix introduces another (minor) bug. Test-cases added. Still to be fixed.

jan.nijtmanswiki2023-02-13 08:40:31

Fixed [here]

Thanks, Ashok, for the bug-report!

jan.nijtmanswiki2023-02-13 10:14:47

After merging the fix to 9.0, it turns out that (new) testcase encoding-16.15 still fails there (it passes in 8.7). So, cannot close this ticket yet, but moving it 8.7 -> 9.0.

apnadkarnimarkdown2023-02-15 05:38:31

I think there is still an issue even with 8.7, not just 9.

% codepoints [encoding convertfrom -strict -failindex idx utf-32le \x41\x00\x00\x00\x00\xD8\x00\x00\x42\x00\x00\x00]
U+000041 U+00FFFD
% set idx
4

idx is correct but the return value has an extra character.

This is with checkout [84f30c5d4e]

/Ashok

jan.nijtmanswiki2023-02-15 07:30:54

Indeed: [6349e0c2e15e07ab]. Thanks!

jan.nijtmanswiki2023-02-16 21:31:00

Reason for encoding-16.15 failure was in the testcase, not in the code. Fixed now.

So, closing.

Log in (anonymous is fine) to add a comment.