Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 6d48050bb8a68baf033f05d3e3b5975d1cd868074de02859fee204218a292220
Ticket: 7deeddb36f217dac87bc68cb69718a89e3c7d5d7
signed integer overflow in Tcl_ScanObjCmd()
User & Date: chrstphrchvz on 2022-02-16 08:57:16
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    Setting <tt>Tcl_WideInt wideValue</tt> to the highest value representable by <tt>Tcl_WideInt</tt> and then doing <tt>wideValue++</tt> is signed integer overflow (undefined behavior).
    
    UBSan (<tt>-fsanitize=signed-integer-overflow</tt>) error when <tt>Tcl_WideInt</tt> is <tt>long long</tt>:
    
    <blockquote><pre>
    % scan -0x18000000000000000 {%li}
    <span style="font-weight:bold">tcl/generic/tclScan.c:926:13:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long long int'</span>
    -9223372036854775808
    </pre></blockquote>
    
    Likewise when <tt>Tcl_WideInt</tt> is <tt>long</tt>:
    
    <blockquote><pre>
    % scan -0x18000000000000000 {%li}
    <span style="font-weight:bold">tcl/generic/tclScan.c:926:13:<span style="color:red"> runtime error: </span>signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'Tcl_WideInt' (aka 'long')</span>
    -9223372036854775808
    </pre></blockquote>
    
    Increment only after casting to <tt>Tcl_WideUInt</tt> if wraparound behavior is desired (without e.g. <tt>-fwrapv</tt>); see attached patch.
    
  5. foundin changed to: "core-8-6-branch"
  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: "23. [scan]"
  14. title changed to: "signed integer overflow in Tcl_ScanObjCmd()"
  15. type changed to: "Patch"