Artifacts Associated With Ticket 9563b8eeec
Ticket change [87b1bb42e9] (rid 254515) by dkf on 2026-06-21 19:05:03:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
Had an AI report [this PR](https://github.com/tcltk/tcl/pull/41) on Github. Patch is totally unusable, but principle is something we should audit for. ## Description (from PR) > The ZlibTransformInput function processes compressed data from a channel without enforcing limits on total decompressed output size. A small compressed payload (zip bomb) can expand to gigabytes of data, exhausting system memory. The function continues to inflate data as long as the caller requests more bytes, with no built-in protection against excessive expansion ratios. > Exploitation scenario: An attacker sends a crafted compressed payload (e.g., a 1KB gzip stream that decompresses to 1GB) through a Tcl channel configured with zlib decompression (e.g., via 'zlib push decompress $chan'). ## Proposed Fix (from PR) At line 3313, add this (in `ZlibTransformInput`, shortly after call to `ResultDecompress`): > ``` > /* > * Guard against decompression bombs: if total decompressed output > * exceeds 1 GiB, return an error to prevent memory exhaustion. > */ > if (chanDataPtr->inStream.total_out > (1024UL*1024UL*1024UL)) { > *errorCodePtr = EFBIG; > return -1; > } > ``` - foundin initialized to: "8.6"
- is_private initialized to: "0"
- login: "dkf"
- priority initialized to: "5 Medium"
- private_contact initialized to: "f6b536f9c1ed4b589e96e38fb613afc3d8991783"
- resolution initialized to: "None"
- severity initialized to: "Severe"
- status initialized to: "Open"
- submitter initialized to: "dkf"
- subsystem initialized to: "57. zlib"
- title initialized to: "Possible zlib compression bomb vulnerabilities"
- type initialized to: "Bug"
Ticket change [47497d0f49] (rid 254516) by dkf on 2026-06-21 19:10:44:
- icomment:
Deeper review: _technically_ this isn't a high-priority bug, as it is part of the streaming system, and that never accepts an unbounded buffer's-worth of input into the next stage of the stream (which may occur possibly many times). It's _possible_ for the code to be used unwisely (e.g., with an unbounded `read $f` call) but it's definitely not guaranteed; the flaw at that level would still exist even without the use of a decompression bomb, and code that deals with untrusted inputs _needs_ to guard against very large inputs (and not just by looking at metadata delivered prior to starting the read). The _principle_ of checking for total decompression lengths is valid. As this is technically not a reported direct vulnerability, I'm not going to worry about reopening 8.6 for it; earliest likely point of any addressing of this is in the 9.0 series.
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [ac7ecccae9] (rid 254517) by dkf on 2026-06-21 19:19:45:
- icomment:
Curiously, the AI missed `Tcl_ZlibInflate` which is more vulnerable.
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [6c76db6c7a] (rid 254566) by dkf on 2026-06-24 15:56:56:
- icomment:
After thinking about this more, I'm going to be using this sort of thing as a test case rather than as an arbitrary guard rail. Code that reads from really untrusted sources needs to bound the amount that it actually reads. Compression algorithms don't change that at all (after all, checking the file size ahead of time leaves TOCTOU vulnerabilities). Tcl doesn't impose a policy limit on how much is accepted (as it depends on the application) but does give the tools to let user code decide that. We _may_ choose to provide a way to let `zlib inflate` (and `zlib decompress` and `zlib gunzip`, which are really the same thing in this respect) impose a limit on the amount of data produced, but _both the stream and channel APIs already have such capabilities available_ (and streams always store compressed data) in that they allow taking fixed/bounded-size pieces of the data, and the user can decide how many to take before rejecting. The tools for mitigating this sort of thing exist, and have existed all along since the inception of the modern `zlib` command in 8.6. Tcl _does not_ prevent users from writing something silly if they want. Adding arbitrary restrictions, such as on how much data can be compressed or what compression ratio may be used, prevents other conforming applications from doing what they want. High memory consumption _may_ be a problem in some cases, but it's not in all and we shouldn't fussily prevent it.
- login: "dkf"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [0cc3c7ffe2] (rid 254567) by dkf on 2026-06-24 15:57:31:
- closedate changed to: "2461216.1649474306"
- closer changed to: "dkf"
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Invalid"
- severity changed to: "Cosmetic"
- status changed to: "Closed"
Ticket change [d361256b68] (rid 254568) by dkf on 2026-06-24 16:09:12:
- closedate changed to: "2461216.17306419"
- icomment:
Test case won't be backported to 8.6, but is applied to 9.0 (and will be merged to 9.1 at some point). It's marked `nonPortable` because it is memory-hungry.
- login: "dkf"
- mimetype: "text/x-markdown"