Overview
| Artifact ID: | d29e03a74692ffa9b896a7eda2f474c0c9af4659c22ec0469a48cc83c25b7428 |
|---|---|
| Ticket: | 9c7557160fd1fb402aa1eb3ec4b358cfa79d596f
signed integer overflow in UpdateStringOfByteArray() |
| User & Date: | chrstphrchvz on 2022-02-18 20:07:21 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed 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 changed to: "core-8-6-branch"
- is_private changed to: "0"
- login: "chrstphrchvz"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "chrstphrchvz"
- subsystem changed to: "12. ByteArray Object"
- title changed to:
signed integer overflow in UpdateStringOfByteArray()
- type changed to: "Patch"