signed integer overflow in Tcl_SetObjLength(), Tcl_AttemptSetObjLength()
Closed / Fixed112e7aa36dbfc3e12be9b32968593729ca6f6264Created 5 years agoUpdated 5 years ago
Descriptionwiki2022-03-05 22:48:06
Calling Tcl_SetObjLength(…, INT_MAX) or Tcl_AttemptSetObjLength(…, INT_MAX) leads to signed integer overflow. The attached patch avoids this.
Example UBSan error:
tcl/generic/tclStringObj.c:961:27: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
Example test case to add to stringObj.test (likely not desirable for Tcl to adopt—will panic on systems with insufficient memory):
test stringObj-4.99 {Tcl_SetObjLength procedure, string lengthened to INT_MAX} testobj {
testobj freeallvars
teststringobj set 1 abcdef
teststringobj setlength 1 [expr 2**31-1]
list [teststringobj length 1]
} [list [expr 2**31-1]]
Referenced by1
2699f682aeFix [112e7aa36d]: signed integer overflow in Tcl_SetObjLength(), Tcl_AttemptSetObjLength() check-in2022-03-06 15:49:31
jan.nijtmanswiki2022-03-06 16:00:59
Fixed [here]
Thanks for the report and the patch!
Log in (anonymous is fine) to add a comment.