From 25816c7fd6cd68420d8ceef59a8b81faf975a877 Mon Sep 17 00:00:00 2001 From: dach-a Date: Tue, 17 Nov 2026 03:31:36 +0000 Subject: [PATCH 1/2] test: make the gzip fixture compressible on every toolchain TestDecodeEvidenceBodyGzipQuoteFound built its body from the 60-byte decodeHTML constant and guarded with "the stream must not contain admin". That assumes the encoder always deflates, and Go 1.27's flate does not: for this input it emits a stored block, the stream is 85 bytes, and the raw bytes are the plaintext the guard rejects. The test then fails on the encoder's choice rather than on the decode it is meant to cover. Repeat the body so it has something to compress, and assert the decoded output equals it, so the guard measures the round trip instead of one encoder's block selection. The quote and the body's content are unchanged, and the sibling truncated/deflate tests already use repeated input. --- server/finding_verification_decode_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/finding_verification_decode_test.go b/server/finding_verification_decode_test.go index 2666744..986384a 100644 --- a/server/finding_verification_decode_test.go +++ b/server/finding_verification_decode_test.go @@ -59,7 +59,16 @@ func decodeSnapshot(t *testing.T, respHead string, raw []byte) (*evidence.Store, } func TestDecodeEvidenceBodyGzipQuoteFound(t *testing.T) { - raw := gzipBody(t, []byte(decodeHTML)) + // A body of a few dozen bytes is not worth deflating: some encoders emit a + // stored block instead, so the stream carries the plaintext verbatim and the + // guard below fails on the encoder's choice rather than on the decode. Give + // the fixture enough redundancy that any encoder compresses it. The quote + // stays the same and still has to survive the round trip. + body := strings.Repeat(decodeHTML, 200) + raw := gzipBody(t, []byte(body)) + if !bytes.HasPrefix(raw, []byte{0x1f, 0x8b}) { + t.Fatal("fixture is not gzip") + } if strings.Contains(string(raw), "admin") { t.Fatal("fixture is not compressed") } @@ -67,8 +76,8 @@ func TestDecodeEvidenceBodyGzipQuoteFound(t *testing.T) { if err != nil || truncated { t.Fatalf("decode: truncated=%v err=%v", truncated, err) } - if string(out) != decodeHTML { - t.Fatalf("decoded %q, want %q", out, decodeHTML) + if string(out) != body { + t.Fatalf("decoded %d bytes, want %d", len(out), len(body)) } if !strings.Contains(normalizeEvidenceText(string(out)), normalizeEvidenceText(decodeQuote)) { t.Fatalf("quote %q not found in decoded body", decodeQuote) From fa33d4dac0828d9a6ef2cdd2481e66e2e63bdf90 Mon Sep 17 00:00:00 2001 From: dach-a Date: Tue, 17 Nov 2026 03:49:25 +0000 Subject: [PATCH 2/2] test: assert compression by size, not by looking for a word The plaintext-substring guard encoded one encoder's output shape: it only held while a small input compressed to fewer bytes than it started with, and Go 1.27 stores instead. Comparing sizes states the same invariant without assuming how flate picks between stored and compressed blocks: a stored block is larger than its input by construction, so "output is under half the input" is true for any working encoder on a repetitive body and false for a body that was never compressed. Checked against the old 60-byte fixture on go1.27.4: it fails with "fixture is not compressed: 60 bytes in, 85 bytes out", so the guard still catches the case it was written for. --- server/finding_verification_decode_test.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/finding_verification_decode_test.go b/server/finding_verification_decode_test.go index 986384a..f4c9432 100644 --- a/server/finding_verification_decode_test.go +++ b/server/finding_verification_decode_test.go @@ -60,24 +60,26 @@ func decodeSnapshot(t *testing.T, respHead string, raw []byte) (*evidence.Store, func TestDecodeEvidenceBodyGzipQuoteFound(t *testing.T) { // A body of a few dozen bytes is not worth deflating: some encoders emit a - // stored block instead, so the stream carries the plaintext verbatim and the - // guard below fails on the encoder's choice rather than on the decode. Give - // the fixture enough redundancy that any encoder compresses it. The quote - // stays the same and still has to survive the round trip. + // stored block instead, and then the round trip below tests nothing. Give + // the fixture enough redundancy that any encoder compresses it, and assert + // the compression itself by size rather than by looking for a word in the + // output: a stored block is larger than its input by construction, so size + // states the real invariant without assuming how a particular flate version + // picks between stored and compressed blocks (#276). body := strings.Repeat(decodeHTML, 200) raw := gzipBody(t, []byte(body)) if !bytes.HasPrefix(raw, []byte{0x1f, 0x8b}) { t.Fatal("fixture is not gzip") } - if strings.Contains(string(raw), "admin") { - t.Fatal("fixture is not compressed") + if len(raw) >= len(body)/2 { + t.Fatalf("fixture is not compressed: %d bytes in, %d bytes out", len(body), len(raw)) } out, truncated, err := decodeEvidenceBody(decodeGzipHead, raw, verificationReadCap) if err != nil || truncated { t.Fatalf("decode: truncated=%v err=%v", truncated, err) } - if string(out) != body { - t.Fatalf("decoded %d bytes, want %d", len(out), len(body)) + if !bytes.Equal(out, []byte(body)) { + t.Fatalf("decoded %d bytes, want the %d byte body", len(out), len(body)) } if !strings.Contains(normalizeEvidenceText(string(out)), normalizeEvidenceText(decodeQuote)) { t.Fatalf("quote %q not found in decoded body", decodeQuote)