Skip to content
Tcl Source Code History Of Ticket 9c7557160
Login

History Of Ticket 9c7557160

Artifacts Associated With Ticket 9c7557160

  1. Ticket change [d29e03a746] (rid 198332) by chrstphrchvz on 2022-02-18 20:07:21:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. 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 &#91;open /dev/zero &#91;list RDONLY BINARY&#93;&#93;
      fconfigure $f -buffersize &#91;expr {2**20}&#93;
      set z &#91;read $f &#91;expr {2**30}&#93;&#93;
      puts &#91;::tcl::mathop::ni $z &#91;list&#93;&#93;
      </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 &#91;open /dev/zero &#91;list RDONLY BINARY&#93;&#93;
      fconfigure $f -buffersize &#91;expr {2**20}&#93;
      set a &#91;encoding convertto utf-8 a&#93;
      set z &#91;read $f &#91;expr {2**30 - 1}&#93;&#93;
      set az &#91;string cat $a $z&#93;
      puts &#91;::tcl::mathop::ni $az &#91;list&#93;&#93;
      </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>.)
      
    5. foundin initialized to: "core-8-6-branch"
    6. is_private initialized to: "0"
    7. login: "chrstphrchvz"
    8. priority initialized to: "5 Medium"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "chrstphrchvz"
    13. subsystem initialized to: "12. ByteArray Object"
    14. title initialized to:
      signed integer overflow in UpdateStringOfByteArray()
      
    15. type initialized to: "Patch"
  2. Add attachment "usoba.diff" [7044e8d703] (rid 198333) by chrstphrchvz on 2022-02-18 20:07:42.

  3. Ticket change [95f8077137] (rid 198880) by jan.nijtmans on 2022-03-08 15:33:47:

    1. assignee changed to: "jan.nijtmans"
    2. closedate changed to: "2459647.14846868"
    3. closer changed to: "jan.nijtmans"
    4. icomment: "Fixed [5e793d379a|here]. Thanks!"
    5. login: "jan.nijtmans"
    6. mimetype: "text/x-fossil-wiki"
    7. resolution changed to: "Fixed"
    8. status changed to: "Closed"
  4. Ticket change [7fd0982c5d] (rid 199070) by dgp on 2022-03-11 16:49:11:

    1. closedate changed to: "2459650.20083206"
    2. closer changed to: "dgp"
    3. icomment:
      
      Alternative patch to consider found on bug-9c7557160f branch.
      
      Leaves behind fewer typecasts for future code readers to puzzle over.
      
    4. login: "dgp"
    5. mimetype: "text/plain"
  5. Ticket change [8d8dca38f4] (rid 199073) by jan.nijtmans on 2022-03-11 17:21:28:

    1. closedate changed to: "2459650.22324207"
    2. closer changed to: "jan.nijtmans"
    3. icomment: "@dgp, I like your alternative! Just go ahead."
    4. login: "jan.nijtmans"
    5. mimetype: "text/x-fossil-wiki"