summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-07-02 02:41:59 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-07-02 02:41:59 (GMT)
commit01785b73fb66a95f79452b4f16a517621c0e04d9 (patch)
treeb06a6e9e862a9be6ad3e6dfdd414f14075b84d80
parent04249bbcd7751a80282d824f8d0bc67aa41e472e (diff)
parentcfc103c6b8a43f7910dda55b8069350921c3f3c7 (diff)
downloadtcl-01785b73fb66a95f79452b4f16a517621c0e04d9.zip
tcl-01785b73fb66a95f79452b4f16a517621c0e04d9.tar.gz
tcl-01785b73fb66a95f79452b4f16a517621c0e04d9.tar.bz2
Fix [66ffafd309]. DBCS infinite loop on invalid encoding
-rw-r--r--generic/tclEncoding.c9
-rw-r--r--tests/chanio.test2
-rw-r--r--tests/io.test2
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