Tcl Source Code

View Ticket
Login
Ticket UUID: 7346adc50fac47b5e7d3c7921d107457883846cc
Title: Crash with encoding convertfrom iso2022-jp <string with escape sequence>
Type: Bug Version: 9.0.1
Submitter: anonymous Created on: 2025-05-25 15:52:49
Subsystem: 11. Conversions from String Assigned To: apnadkarni
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2025-05-26 10:34:54
Resolution: Fixed Closed By: apnadkarni
    Closed on: 2025-05-26 10:34:54
Description:
I hit an "Illegal instruction" crash while trying to parse old archived usenet posts with the mime library.  I can reproduce the issue with a single line:

% ::encoding convertfrom iso2022-jp "\x1b\$B\$*;n\$"
unable to realloc 82463372083200 bytes
Illegal instruction

The same code works without crashing in Tcl 8.6.10:

% ::encoding convertfrom iso2022-jp "\x1b\$B\$*;n\$"
お試
%

I have not dug into the C code involved here, but I would suspect that some length calculation has got broken in the 32->64bit transition.
User Comments: apnadkarni added on 2025-05-26 10:34:54:
Thanks for the review, Jan and @cgm for the report. Fixed now in [237ff71b86].

jan.nijtmans added on 2025-05-26 08:02:27:

Good catch! Looks good to me. I agree with handling tcl8 the same as replace here, the tcl 8.6 behavior is simply broken (too).

I don't think it's really worth to backport the fix to 8.6 too.


apnadkarni added on 2025-05-26 05:17:43:
Proposed fix in [0ca96a7829] ready for review.

apnadkarni added on 2025-05-25 17:20:53:
% tcl::unsupported::icu convertfrom iso2022-jp "\x1b\$B\$*;n\$"
ICU error while decoding. ICU error (11): U_TRUNCATED_CHAR_FOUND

so ICU sees the string as not valid but of course that is no excuse for Tcl to go into a tizzy instead of raising an error.


apnadkarni added on 2025-05-25 16:45:55:
Reproduced. Looking into it...