Skip to content

Conversation

Copy link

Copilot AI commented Dec 4, 2025

The Read function in archive_zip.go was incorrectly attempting to skip reading compressed bytes by seeking to a pre-computed offset, leaving zeros at the start of the buffer. This caused flate: corrupt input before offset 5 errors because deflate streams cannot be decoded from arbitrary offsets due to the sliding window compression mechanism.

Changes

  • Remove incorrect compressed data skipping optimization in gozipArchiveEntry.Read()
  • Always read entire compressed data before passing to gzran.NewDReader
  • The gzran Index is still used for efficient seeking within the uncompressed output

Before (buggy)

compressedData := make([]byte, e.file.CompressedSize64)
f.(io.Seeker).Seek(lastCompressedOffset, io.SeekStart)
_, err := io.ReadFull(f, compressedData[lastCompressedOffset:])  // zeros before offset
fzr, err := gzran.NewDReader(bytes.NewReader(compressedData))   // fails: invalid data at start

After

compressedData := make([]byte, e.file.CompressedSize64)
_, err := io.ReadFull(f, compressedData)  // read complete stream
fzr, err := gzran.NewDReader(bytes.NewReader(compressedData))

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fixes for inefficient reads of ZIP entries Fix flate corrupt input error when reading ZIP entries with gzran Dec 4, 2025
Copilot AI requested a review from chocolatkey December 4, 2025 07:16
@chocolatkey chocolatkey closed this Dec 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants