Skip to content
Tcl Source Code History Of Ticket 69b4f7eb37
Login

History Of Ticket 69b4f7eb37

Artifacts Associated With Ticket 69b4f7eb37

  1. Ticket change [5e4cad2b3e] (rid 198796) by chrstphrchvz on 2022-03-06 20:28:47:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      Running this example leads to signed integer overflow in <tt>FilterInputBytes()</tt> (as reported by UBSan <tt>-fsanitize=signed-integer-overflow</tt>):
      
      <pre>
      $ dd bs=4096 count=250000 if=/dev/zero | tclsh8.6
      <span style="font-weight:bold">tcl/generic/tclIO.c:5330:22:<span style="color:firebrick"> runtime error: </span>signed integer overflow: 1912594432 + 1912594432 cannot be represented in type 'int'</span>
      </pre>
      
      
      But something else I notice is that once <tt>FilterInputBytes()</tt> stops growing <tt>objPtr</tt> exponentially, it falls back to growing linearly by a very small amount (58 bytes in this example), with each growth requiring <tt>realloc()</tt>—which even if [http://blog.httrack.com/blog/2014/04/05/a-story-of-realloc-and-laziness/|made much faster by using Linux’s <tt>mremap()</tt>] will still cause throughput to drop dramatically. While the overflow can be avoiding by capping <tt>length</tt> to <tt>INT_MAX</tt>, low-memory systems—or systems with plenty of memory if <tt>FilterInputBytes()</tt> is rewritten to use <tt>size_t</tt> for Tcl 9—still have the slow linear growth performance issue, so it may still be desirable to improve the <tt>objPtr</tt> growth algorithm to minimize the number of <tt>realloc()</tt> calls. One approach I think of is something that approximates logistic growth: if <tt>length = offset + offset</tt> fails, try again with <tt>length = offset + (offset >> 1)</tt>; otherwise try <tt>length = offset + (offset >> 2)</tt>; and so on until whatever reasonable minimum.
      
    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: "24. Channel Commands"
    14. title initialized to:
      FilterInputBytes(): signed integer overflow, poor worst-case performance lengthening objPtr
      
    15. type initialized to: "Bug"
  2. Ticket change [6636cf6393] (rid 200107) by chrstphrchvz on 2022-04-13 18:34:58:

    1. icomment:
      Apparently there are other places in Tcl where objects are first grown exponentially, and then linearly once doubling is not possible. I would think those are affected by performance issues similar to the one seen in <tt>FilterInputBytes()</tt>, but maybe that is avoided by their use of <tt>TCL_MIN_GROWTH</tt>.
      
      Without a more rigorous analysis, the alternative growth algorithm I suggest (i.e. to approximate logistic growth) may increase the likelihood that a program terminates (due to wasted memory starving other needed allocations) rather than eventually finishes.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [dc326a73b4] (rid 259054) by serhiy.storchaka on 2026-10-18 16:44:59:

    1. foundin changed to: "8.6.18, 9.1.0"
    2. icomment:
      Still present in 9.1 (9.0 has the same code): <tt>Tcl_GetsObj()</tt>, <tt>TclGetsObjBinary()</tt> and <tt>FilterInputBytes()</tt> keep offsets and counts in <tt>int</tt>, so <nowiki>[gets]</nowiki> of a line over 2 GB panics in <tt>Tcl_SetObjLength</tt> ("length requested is negative"), returns a negative length with <tt>-translation binary</tt>, or crashes when a <tt>\r</tt> ends a buffer.
      
      Proposed fix in branch [/timeline?r=gets-long-lines|gets-long-lines]: <tt>Tcl_Size</tt> there, and the doubling of the buffer no longer overflows. Tests gets-bigdata-1 to 3 (constraint <tt>bigdata</tt>, about 6 GB of memory). The growth strategy when doubling fails is unchanged.
      
    3. login: "serhiy.storchaka"
    4. mimetype: "text/x-fossil-wiki"