Overview
| Artifact ID: | 5e4cad2b3e2558cea9d678fc93b0bc4060a82a860b1a4819d8ee3717f42ebd48 |
|---|---|
| Ticket: | 69b4f7eb379e7b806c0c144a36059ca55f569634
FilterInputBytes(): signed integer overflow, poor worst-case performance lengthening objPtr |
| User & Date: | chrstphrchvz on 2022-03-06 20:28:47 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/x-fossil-wiki"
- comment changed 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.
- foundin changed to: "core-8-6-branch"
- 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: "24. Channel Commands"
- title changed to:
FilterInputBytes(): signed integer overflow, poor worst-case performance lengthening objPtr
- type changed to: "Bug"