test: make gzip decompression-bomb regression test actually bite#7655
test: make gzip decompression-bomb regression test actually bite#7655anxkhn wants to merge 1 commit into
Conversation
TestParseProtoReader_GzipDecompressionBomb only asserted that an error was returned, which passes whether or not the io.LimitReader cap on gzip output is present. The compressed input is already bounded by an outer LimitReader and a truncated bomb is rejected by the deferred size check regardless, so neither the returned error nor the bytes read from the source distinguish the two cases. The only real signal is how much is decompressed into memory. Replace the test with a white-box TestDecompressRequest_GzipDecompressionBomb that calls decompressRequest directly and asserts the buffered body never exceeds maxSize+1. This is deterministic and parallel-safe, unlike the process-wide, monotonic runtime.MemStats.TotalAlloc, which concurrent goroutines or parallel tests would inflate. Removing the cap inflates the bomb to ~4 MB in the buffer, blowing past maxSize+1 and failing the test. Also add TestParseProtoReader_Gzip covering the under-cap decode and over-cap rejection through the public API, which had no gzip coverage. Fixes cortexproject#7581. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
|
Good point, |
What this PR does:
TestParseProtoReader_GzipDecompressionBombwas added in #7515 to guard theio.LimitReader(gzReader, maxSize+1)cap on gzip decompression, but it only asserted that an error was returned. That passes whether or not the cap is present because the oversized body is rejected either way.This replaces that test with a deterministic white-box regression test that calls
decompressRequestdirectly and asserts the buffered body never exceedsmaxSize+1. Unlike the earlierruntime.MemStats.TotalAllocapproach, this checks a local slice length, so unrelated process allocations cannot affect it. Removing the cap inflates the test payload to several megabytes and fails the assertion.It also adds
TestParseProtoReader_Gzipcovering successful under-cap decoding and over-cap rejection through the public API.Test-only change; no production code, config, or flags touched.
Which issue(s) this PR fixes:
Fixes #7581
Checklist
CHANGELOG.mdupdated (n/a, not user-facing)docs/configuration/v1-guarantees.mdupdated (n/a, no flags)