From 2bc844ee6103b696341a49471260cd58963a0b51 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 3 Apr 2020 20:56:42 +0000 Subject: Fix testing command [testnumutfchars] so it cannot overrun the buffer. --- generic/tclTest.c | 10 +++++++--- tests/utf.test | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 3e8cb6a..f63f891 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -6805,12 +6805,16 @@ TestNumUtfCharsCmd( Tcl_Obj *const objv[]) { if (objc > 1) { - int len = -1; + int numBytes, len, limit = -1; + const char *bytes = Tcl_GetStringFromObj(objv[1], &numBytes); if (objc > 2) { - (void) Tcl_GetIntFromObj(interp, objv[2], &len); + (void) Tcl_GetIntFromObj(interp, objv[2], &limit); + if (limit > numBytes) { + limit = numBytes; + } } - len = Tcl_NumUtfChars(Tcl_GetString(objv[1]), len); + len = Tcl_NumUtfChars(bytes, limit); Tcl_SetObjResult(interp, Tcl_NewIntObj(len)); } return TCL_OK; diff --git a/tests/utf.test b/tests/utf.test index 2e4882d..5cd2277 100644 --- a/tests/utf.test +++ b/tests/utf.test @@ -137,7 +137,7 @@ test utf-4.9 {Tcl_NumUtfChars: #u20AC, calc len, incomplete} {testnumutfchars te testnumutfchars [testbytestring "\xE2\x82\xAC"] 2 } {2} test utf-4.10 {Tcl_NumUtfChars: #u0000, calc len, overcomplete} {testnumutfchars testbytestring} { - testnumutfchars [testbytestring "\x00"] 2 + testnumutfchars [testbytestring "\x00"] 1 } {2} test utf-5.1 {Tcl_UtfFindFirst} {testfindfirst testbytestring} { -- cgit v0.12 From 57d80b8062bd84389ce200cf7fd42c52b5466b07 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 5 Apr 2020 20:11:49 +0000 Subject: Revert test-case utf-4.10 change from previous commit: It caused the Travis build failure. Change the testnumutfchars command to accept "end+1" as lenght, in which case it will count the ending null-byte too, as test-case 4.10 demands. --- generic/tclTest.c | 8 +++++--- tests/utf.test | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index f63f891..e187ec2 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -6809,9 +6809,11 @@ TestNumUtfCharsCmd( const char *bytes = Tcl_GetStringFromObj(objv[1], &numBytes); if (objc > 2) { - (void) Tcl_GetIntFromObj(interp, objv[2], &limit); - if (limit > numBytes) { - limit = numBytes; + if (TclGetIntForIndex(interp, objv[2], numBytes, &limit) != TCL_OK) { + return TCL_ERROR; + } + if (limit > numBytes + 1) { + limit = numBytes + 1; } } len = Tcl_NumUtfChars(bytes, limit); diff --git a/tests/utf.test b/tests/utf.test index 5cd2277..2e4882d 100644 --- a/tests/utf.test +++ b/tests/utf.test @@ -137,7 +137,7 @@ test utf-4.9 {Tcl_NumUtfChars: #u20AC, calc len, incomplete} {testnumutfchars te testnumutfchars [testbytestring "\xE2\x82\xAC"] 2 } {2} test utf-4.10 {Tcl_NumUtfChars: #u0000, calc len, overcomplete} {testnumutfchars testbytestring} { - testnumutfchars [testbytestring "\x00"] 1 + testnumutfchars [testbytestring "\x00"] 2 } {2} test utf-5.1 {Tcl_UtfFindFirst} {testfindfirst testbytestring} { -- cgit v0.12 From de914c0ed5be4090e8f066359dab792e7cb0c90f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 5 Apr 2020 20:28:06 +0000 Subject: Partial fix for [31aa44375de2c87e]: Tcl_NumUtfChars regression in default 8.6 build. This commit brings Tcl_UtfCharComplete() into agreement with Tcl_UtfToUniChar(), whether it demands 1, 3 or 4 succeeding bytes. --- generic/tclUtf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/generic/tclUtf.c b/generic/tclUtf.c index 6782df9..410268d 100644 --- a/generic/tclUtf.c +++ b/generic/tclUtf.c @@ -64,11 +64,16 @@ static const unsigned char totalBytes[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +#if TCL_UTF_MAX > 4 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +#else /* Tcl_UtfCharComplete() might point to 2nd byte of valid 4-byte sequence */ + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, + 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, +#endif 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, -#if TCL_UTF_MAX > 3 +#if TCL_UTF_MAX > 4 4,4,4,4,4, #else 3,3,3,3,3, /* Tcl_UtfCharComplete() only checks TCL_UTF_MAX bytes */ -- cgit v0.12