Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2022-03-06
16:00 • Closed ticket [112e7aa36d]: signed integer overflow in Tcl_SetObjLength(), Tcl_A... artifact: 89c227a3bd user: jan.nijtmans
15:49
Fix [112e7aa36d]: signed integer overflow in Tcl_SetObjLength(), Tcl_AttemptSetObjLength() check-in: 2699f682ae user: jan.nijtmans tags: core-8-6-branch
2022-03-05
22:48 • Add attachment 112e7aa36d.diff to ticket [112e7aa36d] artifact: a01e9b22d1 user: chrstphrchvz
22:48 • New ticket [112e7aa36d] signed integer overflow in Tcl_SetObjLength(), Tcl_Attem... artifact: 9241e84ed8 user: chrstphrchvz

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.