From e48f5ef287515b6c7d57980491e95f96f34cb0d7 Mon Sep 17 00:00:00 2001 From: Stephen Gelman Date: Tue, 22 Sep 2026 01:05:25 -0500 Subject: [PATCH] pack/packfile_test.go: derive offsets from compressed size Two of the packfile tests build a small pack in memory and then point into it with byte offsets written as constants. Those constants only hold if zlib turns "Hello" into 17 bytes and "Hello!\n" into 19, which was true through Go 1.26. Go 1.27 breaks that. It writes these short inputs as a stored block, so each comes out one byte longer. The OFS_DELTA test then points one byte past the base object's header and lands on the zlib header byte, which decodes as an OBJ_REF_DELTA. The index lookup fails with "object not found in index" and the test panics on the nil object. The REF_DELTA test has the same problem with its index entry. Both values are now computed from len(compressed), so the tests stop depending on how many bytes the compressor emits. Tested with Go 1.25.0, 1.26.0 and 1.27.1. --- pack/packfile_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pack/packfile_test.go b/pack/packfile_test.go index 3f7db0e..1dc9e6a 100644 --- a/pack/packfile_test.go +++ b/pack/packfile_test.go @@ -108,8 +108,8 @@ func TestPackObjectReturnsObjectWithDeltaBaseOffset(t *testing.T) { 0x35, // (0011 0101) (msb=0, type=blob, size=5) }, compressed...), append([]byte{ - 0x6e, // (0110 1010) (msb=0, type=obj_ofs_delta, size=10) - 0x12, // (0001 0001) (ofs_delta=-17, len(compressed)) + 0x6e, // (0110 1010) (msb=0, type=obj_ofs_delta, size=10) + byte(1 + len(compressed)), // ofs_delta: base header byte + len(compressed) }, delta...)...)), hash: sha1.New(), } @@ -147,7 +147,7 @@ func TestPackfileObjectReturnsObjectWithDeltaBaseReference(t *testing.T) { p := &Packfile{ idx: IndexWith(map[string]uint32{ "cccccccccccccccccccccccccccccccccccccccc": 32, - "dddddddddddddddddddddddddddddddddddddddd": 52, + "dddddddddddddddddddddddddddddddddddddddd": uint32(32 + 1 + len(compressed)), }), r: bytes.NewReader(append(append([]byte{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,