lib/suitar: fix Writer block-boundary handling and directory headers - #179
Merged
Merged
Conversation
added 3 commits
September 12, 2026 23:48
Write left w.bIndex at 512 once a full block had been written out, so the next loop iteration took the "partial block" branch, copied zero bytes and went round again forever, writing the same 512 bytes over and over. Calling Write with sizes that aren't multiples of 512 is enough to hit this. It also duplicated the last data block when a Write call happened to end exactly on a block boundary, because flush then saw a non-zero bIndex and wrote the block out a second time.
WriteHeader copied h into w.header before calling w.Write to emit the GNUTYPE_LONGNAME block holding the name. Write only accepts TypeReg and TypeGNUSparse, so a TypeDir header failed that call and left the Writer permanently in an error state - every later entry on the same Writer failed too. Set w.header after the name block has gone out instead.
TestWriterChunked writes one file several times, splitting the contents over Write calls differently each time, and checks the archive bytes come out identical. The capped writer makes a runaway Write fail the test instead of hanging it. TestWriterDir writes a directory and then a file inside it, and reads both back.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Collaborator
|
Thanks! I have a few style nits, but I can fix that myself, after I rebase. Regarding the google-cla, I have confirmed (using Google's internal tools) that GitHub username rootkiller6788 has passed the CLA check. |
nigeltao
added a commit
that referenced
this pull request
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found two bugs in the new lib/suitar Writer while poking at block boundaries.
The first one: Write didn't reset w.bIndex after writing out a full 512-byte block. The next loop iteration then took the "partial block" path, copied nothing and went round forever writing the same block. Calling Write with 300 bytes and then 700 bytes is enough to hit it, the second call never came back. It also duplicated the last data block when a Write happened to end exactly on a block boundary, which the reader then rejects as a bad header. One line fixes it.
The second one: WriteHeader set w.header = *h before calling w.Write to emit the name block (suitar writes each name as a GNUTYPE_LONGNAME entry first). Write refuses anything that isn't TypeReg or TypeGNUSparse, so a TypeDir header blew up there and poisoned the Writer for every later entry too. Moved the assignment to after the name block. Header.Valid(), the exported TypeDir constant and the spec all treat directories as normal, so I think it was just an oversight.
I added TestWriterChunked (writes the same file with different chunk sizes and checks the bytes come out the same) and TestWriterDir (a directory plus a file inside it). Both fail on the old code. The chunked one fails in 0.00s rather than hanging, I put a capped writer in the test for that.
One thing I noticed and left alone: Reader.Next has two
return Header{}, errthat don't latch r.err, unlike the error handling everywhere else in the file. Doesn't seem to cause a problem right now, just inconsistent.go test ./lib/suitar/ passes.