Repository navigation
Conversation
File.Read returned (n, io.EOF) before updating f.offset += n whenever a read consumed the remaining content, causing subsequent Read calls to re-deliver the final chunk with (n, io.EOF) instead of (0, io.EOF) in violation of the io.Reader contract. Also close the underlying embedded file and return (nil, err) when FileSystem.Open fails during gzip reader initialization or decompression. Signed-off-by: Yan Chen <yan8925298@gmail.com>
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.
Summary
Fix two contract bugs in
assets/embed_gzip.go:(*File).Readdoes not advancef.offseton the finalio.EOFchunk:Readcheckedif n == len(f.content)-f.offset { return n, io.EOF }before executingf.offset += n. As a result, once a read reached the end of the decompressed buffer, every subsequentReadcall re-delivered the final chunk (or the entire file) with(n, io.EOF)instead of returning(0, io.EOF), violating Go'sio.Readercontract.FileSystem.Openreturns an unclosed non-nilfs.Fileon gzip error:If
gzip.NewReader(f)orio.ReadAll(gr)failed,Openreturned(f, err)without closingf. It now closesfand returns(nil, err).Verification
assets/embed_gzip_test.go(TestFileReadAfterEOF,TestOpenCorruptGzip) plusassets/testdata/corrupt.gz.TestFileReadAfterEOFfailed withn=4/n=2on subsequent reads afterio.EOF, andTestOpenCorruptGzipfailed with a non-nil*embed.openFile.go test -race -count=1 -v ./...,go vet ./..., andgofmt -l .inassets/all pass.Note: AI-assisted diagnosis and drafting; all code, tests, and local verification were reviewed and executed locally.