Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2025-05-26
10:34 • Closed ticket [7346adc50f]: Crash with encoding convertfrom iso2022-jp <strin... artifact: 9c4eabc7fc user: apnadkarni
10:31
Merge 9.0 - Fix [7346adc50f] - memory runaway on truncated iso2022 encoding check-in: 6b0ee0b290 user: apnadkarni tags: trunk, main
10:29
Fix [7346adc50f] - memory runaway on truncated iso2022 encoding check-in: 237ff71b86 user: apnadkarni tags: core-9-0-branch
08:02 • Ticket [7346adc50f] Crash with encoding convertfrom iso2022-jp <string with e... artifact: 4ccfd50a14 user: jan.nijtmans
05:17 • Ticket [7346adc50f]: 3 changes artifact: 8dec840a7e user: apnadkarni
2025-05-25
17:27
Start on [7346adc50f]. Now raise error on truncated encoding. Still have to handle replace and tcl8 ... check-in: 591e540e6d user: apnadkarni tags: apn-bug-7346adc50f
17:20 • Ticket [7346adc50f] Crash with encoding convertfrom iso2022-jp <string with e... artifact: c5fb1d84e9 user: apnadkarni
16:45 • Ticket [7346adc50f]: 4 changes artifact: 2ec8e55d7d user: apnadkarni
15:52 • New ticket [7346adc50f]. artifact: 780f5275ad user: anonymous

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.