Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 202b980e5ba485bb0e5bf561b315749550bc2a6d4736e3ac85b011d7aa4b11f4
Ticket: 816913a65eabbd69b07be7221b68b10064103a0e
GrowStringBuffer(): signed integer overflow
User & Date: chrstphrchvz on 2021-12-24 19:11:02
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. 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>).
    
  5. foundin changed to: "8.6.12"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. resolution changed to: "None"
  10. severity changed to: "Minor"
  11. status changed to: "Open"
  12. submitter changed to: "chrstphrchvz"
  13. subsystem changed to: "10. Objects"
  14. title changed to: "GrowStringBuffer(): signed integer overflow"
  15. type changed to: "Bug"