Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2020-04-20
05:17
Apply fix for [2738427] and adjust tests. check-in: 27cfa0775d user: dgp tags: dgp-utf-explore
2020-04-19
23:23
We know that Tcl 8.5.19 suffered from [2738427] where Tcl_NumUtfChars did not handle incomplete sequ... check-in: 4e95159d0a user: dgp tags: dgp-utf-explore
2020-04-16
19:53 • Closed ticket [2738427fff]: Tcl_NumUtfChars(...) no overflow check plus 5 ot... artifact: ba5bbee20a user: dgp
19:52
Convert Tcl_UtfNext into a routine that doesn't decode UTF-8 into UCS-2, but sticks only to its task... check-in: 76213b3f72 user: dgp tags: core-8-5-branch
2020-04-14
21:16
Replace calls of TclUtfToUniChar() with TclUtfNext() when caller has no decoding need. Failing test ... check-in: d0cc6cdb7f user: dgp tags: dgp-utf-next
2017-06-08
14:54 • Ticket [2738427fff] Tcl_NumUtfChars(...) no overflow check status still Open... artifact: d07e088e19 user: jan.nijtmans
14:22 • Open ticket [2738427fff]. artifact: 57658785df user: dgp
13:45 • Ticket [2738427fff]: 5 changes artifact: 743cd7c154 user: jan.nijtmans
12:54 • Ticket [2738427fff]: 5 changes artifact: 4308e5f95b user: dgp
12:41 • Closed ticket [2738427fff]. artifact: e889948306 user: jan.nijtmans
12:37
Fix [2738427]: Tcl_NumUtfChars(...) no overflow check. check-in: 6b5843fde9 user: jan.nijtmans tags: core-8-6-branch
12:34
Fix [2738427]: Tcl_NumUtfChars(...) no overflow check. check-in: e376f4b734 user: jan.nijtmans tags: core-8-5-branch
12:26 • Ticket [2738427fff] Tcl_NumUtfChars(...) no overflow check status still Open... artifact: 9aec2b5f75 user: jan.nijtmans
2014-02-21
19:07 • Ticket [2738427fff]: 1 change artifact: c494b2dd0c user: jan.nijtmans
2009-04-11
03:09 • Ticket [2738427fff]: 4 changes artifact: ce3a494437 user: dgp
2009-04-06
19:41 • New ticket [2738427fff]. artifact: 390f21f693 user: dgp

Tcl_NumUtfChars(...) no overflow check

Closed / Fixed2738427fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 7 years ago
Descriptionplain2009-04-06 19:41:37
Tcl_NumUtfChars(unicode, -1) can return negative
counts if there are really more than INT_MAX Utf
chars located at unicode before a terminating \0
is seen.

In addition, there is another overflow problem, e.g.
Tcl_NumUtfChars("\xE2\x82\xAC", 2): This call returns
1 instead of the expected 2.
dgpplain2009-04-11 03:09:53
comment test....
jan.nijtmans Ticket [2738427fff]: 1 change [History diff]2014-02-21 19:07:44
jan.nijtmansplain2017-06-08 12:26:18
Problem with the Tcl_NumUtfChars("\xE2\x82\xAC", 2) call is that
the 3th byte is read, even though a length of only 2 bytes was
requested. Since with only 2 bytes, the unicode character is
incomplete, Tcl_NumUtfChars() should count this as 2 separate bytes.
jan.nijtmanswiki2017-06-08 12:41:17

Fixed in core-8-5-branch, core-8-6-branch and trunk.

For Tcl 9 it would be better to change the signature of Tcl_NumUtfChars (using size_t length parameter and return value in stead of int), but that's out-of-scope for this ticket.

dgpplain2017-06-08 12:54:47
Thanks for finding and addressing this old ticket.

I'm worried it's not quite a correct answer.

The overflow detection is only done after
the loop ends, and not at each pass through
the loop.  This leaves open the possibility
that i could circle all the way back to a
non-negative value before '\0' is seen and
we get a count that's (UINT_MAX + 1) too small.

Since the return type can only handle a value
up to INT_MAX, and since there's no error
reporting channel available, should this routine
just panic for inputs outside that supportable range?
jan.nijtmanswiki2017-06-08 13:45:29

Yes I'm aware that this is not 100% correct yet, in Tcl 9 we can do better. Panicing would be OK to me, it's not a use-case that will be encountered in real life .....

Thank you, Don, for your feedback!

dgpplain2017-06-08 14:22:55
Adding another way for a Tcl-using program
to crash doesn't strike me as a great answer
either. I need more thought on it.

Re-opening and assigning to myself as a
reminder to look again sometime.

Not changing anything checked in though.
It's at least as good as what was there before.
jan.nijtmansplain2017-06-08 14:54:25
Sure, Don, please go ahead! I'm out of ideas for 8.x ....
dgpplain2020-04-16 19:53:06
Fix completed in 8.5 now.
Log in (anonymous is fine) to add a comment.