Artifacts Associated With Ticket 9c7557160fd1fb40
Ticket change [d29e03a746] (rid 198332) by chrstphrchvz on 2022-02-18 20:07:21:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
<tt>int size</tt> overflowing when incremented is undefined behavior. Example script and output showing UBSan (<tt>-fsanitize=signed-integer-overflow</tt>) error: <blockquote><pre> set f [open /dev/zero [list RDONLY BINARY]] fconfigure $f -buffersize [expr {2**20}] set z [read $f [expr {2**30}]] puts [::tcl::mathop::ni $z [list]] </pre></blockquote> <blockquote><pre> <span style="font-weight:bold">tcl/generic/tclBinary.c:568:10:<span style="color:firebrick"> runtime error: </span>signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'</span> max size for a Tcl value (2147483647 bytes) exceeded </pre>(tclsh aborted)</blockquote> If <tt>size</tt> does not overflow, it could instead be <tt>INT_MAX</tt>, causing overflow in <tt>ckalloc(size + 1)</tt>. Example script and output: <blockquote><pre> set f [open /dev/zero [list RDONLY BINARY]] fconfigure $f -buffersize [expr {2**20}] set a [encoding convertto utf-8 a] set z [read $f [expr {2**30 - 1}]] set az [string cat $a $z] puts [::tcl::mathop::ni $az [list]] </pre></blockquote> <blockquote><pre> <span style="font-weight:bold">tcl/generic/tclBinary.c:575:19:<span style="color:firebrick"> runtime error: </span>signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'</span> 1 </pre></blockquote> Casting <tt>size</tt> to <tt>unsigned int</tt> avoids this; see attached patch. (There could be alternatives such as declaring <tt>size<tt> as <tt>unsigned int</tt>.) - foundin initialized to: "core-8-6-branch"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "12. ByteArray Object"
- title initialized to:
signed integer overflow in UpdateStringOfByteArray()
- type initialized to: "Patch"
Add attachment "usoba.diff" [7044e8d703] (rid 198333) by chrstphrchvz on 2022-02-18 20:07:42.
Ticket change [95f8077137] (rid 198880) by jan.nijtmans on 2022-03-08 15:33:47:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2459647.14846868"
- closer changed to: "jan.nijtmans"
- icomment: "Fixed [5e793d379a|here]. Thanks!"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [7fd0982c5d] (rid 199070) by dgp on 2022-03-11 16:49:11:
- closedate changed to: "2459650.20083206"
- closer changed to: "dgp"
- icomment:
Alternative patch to consider found on bug-9c7557160f branch. Leaves behind fewer typecasts for future code readers to puzzle over.
- login: "dgp"
- mimetype: "text/plain"
Ticket change [8d8dca38f4] (rid 199073) by jan.nijtmans on 2022-03-11 17:21:28:
- closedate changed to: "2459650.22324207"
- closer changed to: "jan.nijtmans"
- icomment: "@dgp, I like your alternative! Just go ahead."
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"