Fix StubReader.ReadByte() discarding valid byte on EOF#98
Open
hdrover wants to merge 1 commit intoSagerNet:devfrom
Open
Fix StubReader.ReadByte() discarding valid byte on EOF#98hdrover wants to merge 1 commit intoSagerNet:devfrom
hdrover wants to merge 1 commit intoSagerNet:devfrom
Conversation
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.
StubReader.ReadByte()ignores thenreturn value fromRead().When
Read()returns(n=1, err=io.EOF), which is valid per theio.Readercontract,ReadByte()returns(byte, EOF)instead of(byte, nil). Callers seeerr != niland discard the successfully read byte.This causes
readString()inlibbox/profile_import.goto fail with unexpected EOF when decoding .bpf profile files if the gzip stream delivers the last byte together with EOF.Fix: replace
r.Read()withio.ReadFull(), which returnsnilwhen the requested number of bytes has been fully read, even if the underlyingRead()returned EOF alongside the data.This became a visible regression in sing-box v1.13.0 after commit SagerNet/sing-box@1af14a0 ("Remove varbin usages"), which changed string reading from
io.ReadFull()(tolerant to data+EOF) to a byte-by-byteReadByte()loop, exposing this bug. In v1.12.x profile import worked correctly.Screenshot: sing-box Android app failing to import a valid .bpf file generated with standard gzip (without sync flush).