Overview
| Artifact ID: | 202b980e5ba485bb0e5bf561b315749550bc2a6d4736e3ac85b011d7aa4b11f4 |
|---|---|
| Ticket: | 816913a65eabbd69b07be7221b68b10064103a0e
GrowStringBuffer(): signed integer overflow |
| User & Date: | chrstphrchvz on 2021-12-24 19:11:02 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed to:
In <tt>GrowStringBuffer()</tt> (generic/tclStringObj.c), it is possible for <tt>int attempt</tt> to be assigned <tt>INT_MAX</tt>, such as when the function is called with <tt>int needed = INT_MAX</tt>. When this happens, <tt>int attempt</tt> will also be assigned <tt>INT_MAX</tt>, and <tt>attempt + 1</tt> will overflow (although I do not observe this causing unexpected behavior). [https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks|UBSan (<tt>-fsanitize=signed-integer-overflow</tt>)] error example: <pre> % set dz [open /dev/zero [list RDONLY]] % set nulls [read $dz [expr {(1 << 30) - 1}]] <span style="font-weight:bold">tcl/generic/tclStringObj.c:167:20: <span style="color:red">runtime error:</span> signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'</span> </pre> If it is indeed okay to allocate <tt>(unsigned int)INT_MAX + 1U</tt>, then some possible ways to avoid overflow include declaring <tt>attempt</tt> as <tt>unsigned int</tt>, or changing instances of <tt>attempt + 1</tt> to promote <tt>attempt</tt> to <tt>unsigned int</tt> (such as by using <tt>attempt + 1U</tt>). - foundin changed to: "8.6.12"
- 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: "10. Objects"
- title changed to: "GrowStringBuffer(): signed integer overflow"
- type changed to: "Bug"