Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-06-24
16:09 • Ticket [9563b8eeec] Possible zlib compression bomb vulnerabilities status st... artifact: d361256b68 user: dkf
15:57 • Closed ticket [9563b8eeec]. artifact: 0cc3c7ffe2 user: dkf
15:56 • Ticket [9563b8eeec]: 3 changes artifact: 6c76db6c7a user: dkf
15:40
[9563b8eeec] Add test case with very compressible data check-in: 60d5caaf85 user: dkf tags: core-9-0-branch
2026-06-21
19:19 • Ticket [9563b8eeec] Possible zlib compression bomb vulnerabilities status st... artifact: ac7ecccae9 user: dkf
19:10 • Ticket [9563b8eeec]: 3 changes artifact: 47497d0f49 user: dkf
19:05 • New ticket [9563b8eeec]. artifact: 87b1bb42e9 user: dkf

Possible zlib compression bomb vulnerabilities

Closed / Invalid9563b8eeeca59ca891df8406c80ae71ae6a73b57Created 164 days agoUpdated 161 days ago
Descriptionmarkdown2026-06-21 19:05:03

Had an AI report this PR 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;
	}
Referenced by1
dkfmarkdown2026-06-21 19:10:44

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.

dkfmarkdown2026-06-21 19:19:45

Curiously, the AI missed Tcl_ZlibInflate which is more vulnerable.

dkfmarkdown2026-06-24 15:56:56

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.

dkf Closed ticket [9563b8eeec]. [History diff]2026-06-24 15:57:31
dkfmarkdown2026-06-24 16:09:12

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.

Log in (anonymous is fine) to add a comment.