Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Crash with encoding convertfrom iso2022-jp <string with escape sequence>

Closed / Fixed7346adc50fac47b5e7d3c7921d107457883846ccCreated 2 years agoUpdated 2 years ago
Descriptionplain2025-05-25 15:52:49
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.
Referenced by3
  • 6b0ee0b290Merge 9.0 - Fix [7346adc50f] - memory runaway on truncated iso2022 encoding check-in2025-05-26 10:31:22
  • 237ff71b86Fix [7346adc50f] - memory runaway on truncated iso2022 encoding check-in2025-05-26 10:29:00
  • 591e540e6dStart on [7346adc50f]. Now raise error on truncated encoding. Still have to handle replace and tcl8 profiles. check-in2025-05-25 17:27:37
apnadkarniplain2025-05-25 16:45:55
Reproduced. Looking into it...
apnadkarnimarkdown2025-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.

apnadkarniplain2025-05-26 05:17:43
Proposed fix in [0ca96a7829] ready for review.
jan.nijtmanswiki2025-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.

apnadkarniplain2025-05-26 10:34:54
Thanks for the review, Jan and @cgm for the report. Fixed now in [237ff71b86].
Log in (anonymous is fine) to add a comment.