summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-04-29 16:16:58 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-04-29 16:16:58 (GMT)
commit6c973cf9a204f96f3350a7908067f2707e130afb (patch)
tree9cec16d478c6156328524c310653ab04c471eb13
parent947e3f840513df07d5f854ebe9fcf7e348668878 (diff)
downloadtcl-6c973cf9a204f96f3350a7908067f2707e130afb.zip
tcl-6c973cf9a204f96f3350a7908067f2707e130afb.tar.gz
tcl-6c973cf9a204f96f3350a7908067f2707e130afb.tar.bz2
Add tests. Panic on bytecode length limit
-rw-r--r--generic/tclCompile.c12
-rw-r--r--tests/bigdata.test21
2 files changed, 32 insertions, 1 deletions
diff --git a/generic/tclCompile.c b/generic/tclCompile.c
index 69a8383..926c492 100644
--- a/generic/tclCompile.c
+++ b/generic/tclCompile.c
@@ -870,6 +870,18 @@ TclSetByteCodeFromAny(
}
/*
+ * After optimization is all done, check that byte code length limits
+ * are not exceeded. Bug [27b3ce2997].
+ */
+ if ((compEnv.codeNext - compEnv.codeStart) > INT_MAX) {
+ /*
+ * Cannot just return TCL_ERROR as callers ignore return value.
+ * TODO - May be use TclCompileSyntaxError here?
+ */
+ Tcl_Panic("Maximum byte code length %d exceeded.", INT_MAX);
+ }
+
+ /*
* Change the object into a ByteCode object. Ownership of the literal
* objects and aux data items passes to the ByteCode object.
*/
diff --git a/tests/bigdata.test b/tests/bigdata.test
index a1ccd32..286f930 100644
--- a/tests/bigdata.test
+++ b/tests/bigdata.test
@@ -116,6 +116,26 @@ set ::bigLengths(patlenmultiple) [bigPatlenMultiple $::bigLengths(intmax)]
set ::bigLengths(upatlenmultiple) [bigPatlenMultiple $::bigLengths(uintmax)]
#
+# script limits
+bigtestRO script-length-bigdata-1 {Test script length limit} b -body {
+ try [string cat [string repeat " " 0x7ffffff7] "set a b"]
+}
+# TODO - different behaviour between compiled and uncompiled
+test script-length-bigdata-2.compiled {Test script length limit} -body {
+ try [string cat [string repeat " " 0x7ffffff8] "set a b"]
+} -result {Script length 2147483647 exceeds max permitted length 2147483646.} -returnCodes error
+test script-length-bigdata-2.uncompiled {Test script length limit} -body {
+ testevalex [string cat [string repeat " " 0x7ffffff8] "set a b"]
+} -result b
+test script-bytecode-length-bigdata-1 {Test bytecode length limit} -body {
+ # Note we need to exceed bytecode limit without exceeding script char limit
+ set s [string repeat {{*}$x;} [expr 0x7fffffff/6]]
+ catch $s r e
+} -cleanup {
+ bigClean
+} -constraints panic-in-EnterCmdStartData
+
+#
# string cat
bigtest string-cat-bigdata-1 "string cat large small result > INT_MAX" 1 -body {
string equal \
@@ -159,7 +179,6 @@ bigtestRO string-equal/compare-bigdata-2 "string compare/equal -length unequal s
} -cleanup {
bigClean
}
-# -constraints bug-a814ee5bbd
#
# string first