Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2023-04-16
13:48
Merge trunk [7b54fc6784]: Fix for [885c86a9a0]: convertfrom utf8 breaks for 4 byte utf encodings. check-in: 6914aa7c63 user: pooryorick tags: trunk-encodingdefaultstrict
2023-03-22
12:26
Merge trunk: Fix for [885c86a9a0]: convertfrom utf8 breaks for 4 byte utf encodings. check-in: 5f32330ca2 user: pooryorick tags: unchained
2023-02-22
08:04 • Closed ticket [885c86a9a0]: convertfrom utf8 breaks for 4 byte utf encodings... artifact: 361d23e5c8 user: jan.nijtmans
2023-02-17
19:14
Fix for [885c86a9a0]: convertfrom utf8 breaks for 4 byte utf encodings check-in: c9645172df user: jan.nijtmans tags: core-8-branch
2023-02-16
21:54 • Pending ticket [885c86a9a0]: convertfrom utf8 breaks for 4 byte utf encodings</i... artifact: 2e1dc0ff2d user: jan.nijtmans
07:59
Try to fix [885c86a9a0]. Doesn't work completely yet. check-in: 75fea0971f user: jan.nijtmans tags: bug-885c86a9a0
07:20 • Ticket [885c86a9a0] convertfrom utf8 breaks for 4 byte utf encodings status ... artifact: d58852d14b user: jan.nijtmans
2023-02-15
17:20 • Ticket [885c86a9a0]: 3 changes artifact: cdd22cb0eb user: apnadkarni
17:15 • Ticket [885c86a9a0]: 3 changes artifact: 8e8e038349 user: apnadkarni
16:51 • Ticket [885c86a9a0]: 3 changes artifact: 15103e545c user: jan.nijtmans
16:19 • Ticket [885c86a9a0]: 3 changes artifact: bcdc9a1c57 user: apnadkarni
11:35 • Ticket [885c86a9a0]: 4 changes artifact: 94a08270f2 user: jan.nijtmans
11:04 • New ticket [885c86a9a0]. artifact: 8e367b361d user: apnadkarni

convertfrom utf8 breaks for 4 byte utf encodings

Closed / Fixed885c86a9a0c537862e5895379d454e652a55324bCreated 4 years agoUpdated 4 years ago
Descriptionmarkdown2023-02-15 11:04:39

Consider

% package require Tcl
8.7a6
% codepoints [encoding convertfrom utf-8 \xf0\x80\x80\x80]
U+0000F0 U+0020AC U+000080 U+000080

This should map to U+10000 or at least the equivalent surrogate pair.

Referenced by4
jan.nijtmanswiki2023-02-15 11:35:12

Here, \xf0\x80\x80\x80 is an illegal overlong sequence, so it's split into its bytes. Compare this with Tcl 8.6:

% package require Tcl
8.6.13
% codepoints [encoding convertfrom utf-8 \xf0\x80\x80\x80]
U+0000F0 U+000080 U+000080 U+000080

But now TIP #389 should take it's role, which describes the fallback to cp1252. Therefore, the actual answer should be: U+0000F0 U+0020AC U+0020AC U+0020AC (since byte 0x80 is the euro-sign in cp1252)

Not high prio to fix, since it's an illegal byte sequence anyway. When using -strict it throws an exception:

$ tclsh8.7
% encoding convertfrom -strict utf-8 \xf0\x80\x80\x80
unexpected byte sequence starting at index 0: '\xF0'

apnadkarniplain2023-02-15 16:19:37
I shouldn't do UTF arithmetic in my head, I worked it out to U+10000.

Yes, I know it is an overlong sequence but invalid sequences is what I am testing. 

There is no rush with this, I'm just generating test cases to cover as many combinations of invalid sequences that I can from the Unicode standard tables.
Tedious but half the security related bugs in encoders/decoders seem to come from invalid sequences so I don't consider them unimportant.

/Ashok
jan.nijtmanswiki2023-02-15 16:51:05

> Tedious but half the security related bugs in encoders/decoders seem to come from invalid sequences so I don't consider them unimportant.

Yes, they are important, but the Utf encoders/decoders were already fixed for this possible security issue since 8.6.8 or so. Nothing new for 8.7/9.0

See: [67aa9a2070]

apnadkarniplain2023-02-15 17:15:44
Is this cp1252 mapping supposed to happen only when decoding utf-8 or for all encodings (ascii, shiftjis) ? I don't actually see this specified anywhere. TIP 389 only talks about utf<->unichar mapping.

And I assume the C level behaviour is supposed to map to the script level encoding commands?

/Ashok
apnadkarniplain2023-02-15 17:20:29
> Yes, they are important, but the Utf encoders/decoders were already fixed for this possible security issue since 8.6.8 or so. Nothing new for 8.7/9.0 

I wasn't talking purely about overlong sequences. In general, misbehavior or bugs with invalid sequence handling in whatever form should not be taken lightly. That is why the standard is so particular about conformant error handling.

/Ashok
jan.nijtmanswiki2023-02-16 07:20:49

> Is this cp1252 mapping supposed to happen only when decoding utf-8 or for all encodings (ascii, shiftjis) ? I don't actually see this specified anywhere. TIP 389 only talks about utf<->unichar mapping.

... thinking back to long ago .....

According to the TIP it's built into the utf -> unichar encoder, nowhere else. So it should only apply to utf-8 (and cesu-8), not to any other encoders.

jan.nijtmanswiki2023-02-16 21:54:12

Should be fixed [here]

jan.nijtmanswiki2023-02-22 08:04:55

Fixed [here]

Thanks, Ashok, for the report!

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