From cfc103c6b8a43f7910dda55b8069350921c3f3c7 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sat, 1 Jul 2023 18:02:07 +0000 Subject: Bug [66ffafd309] --- generic/tclEncoding.c | 9 +++++---- tests/chanio.test | 2 +- tests/io.test | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index b02a422..cb252b3 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -3479,19 +3479,19 @@ TableToUtfProc( src++; if (src >= srcEnd) { if (!(flags & TCL_ENCODING_END)) { + /* Suffix bytes expected, don't consume prefix */ src--; result = TCL_CONVERT_MULTIBYTE; break; } else if (PROFILE_STRICT(flags)) { + /* Truncation. Do not consume so error location correct */ src--; result = TCL_CONVERT_SYNTAX; break; } else if (PROFILE_REPLACE(flags)) { ch = UNICODE_REPLACE_CHAR; } else { - src--; /* See bug [bdcb5126c0] */ - result = TCL_CONVERT_MULTIBYTE; - break; + ch = (unsigned) byte; } } else { ch = toUnicode[byte][*((unsigned char *)src)]; @@ -3500,6 +3500,7 @@ TableToUtfProc( ch = pageZero[byte]; } if ((ch == 0) && (byte != 0)) { + /* Prefix+suffix pair is invalid */ if (PROFILE_STRICT(flags)) { result = TCL_CONVERT_SYNTAX; break; @@ -3510,7 +3511,7 @@ TableToUtfProc( if (PROFILE_REPLACE(flags)) { ch = UNICODE_REPLACE_CHAR; } else { - ch = (Tcl_UniChar)byte; + ch = (Tcl_UniChar)byte; } } diff --git a/tests/chanio.test b/tests/chanio.test index cdd5816..5a793d6 100644 --- a/tests/chanio.test +++ b/tests/chanio.test @@ -1104,7 +1104,7 @@ test chan-io-7.3 {FilterInputBytes: split up character at EOF} -setup { lappend x [chan gets $f line] $line } -cleanup { chan close $f -} -result [list 15 "123456789012301" 18 0 1 -1 ""] +} -result [list 16 "123456789012301\x82" 18 0 1 -1 ""] test chan-io-7.4 {FilterInputBytes: recover from split up character} -setup { variable x "" } -constraints {stdio fileevent} -body { diff --git a/tests/io.test b/tests/io.test index a88ee99..0fed043 100644 --- a/tests/io.test +++ b/tests/io.test @@ -1201,7 +1201,7 @@ test io-7.3 {FilterInputBytes: split up character at EOF} {testchannel} { lappend x [gets $f line] $line close $f set x -} [list 15 "123456789012301" 18 0 1 -1 ""] +} [list 16 "123456789012301\x82" 18 0 1 -1 ""] test io-7.4 {FilterInputBytes: recover from split up character} {stdio fileevent} { set f [open "|[list [interpreter] $path(cat)]" w+] fconfigure $f -encoding binary -buffering none -- cgit v0.12