encoding/binary: Read(U)varint should return ErrUnexpectedEOF #33575
Labels
Milestone
Comments
Buggy function that inspired this report: https://github.com/gogo/protobuf/blob/28a6bbf47e48e0b2220b2a244750b660c83d4942/io/varint.go#L109-L126 This function will return |
Checking that a partially read varint is non-zero doesn't work if those bits are all-zero. I just ran into this problem myself and definitely think that EOF after the first byte should be converted to ErrUnexpectedEOF as done by I think any existing code that relies on EOF being returned after the first byte is more likely to be broken with the author unaware of the partial-read behavior. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of Go are you using (
go version
)?Description
binary.ReadUvarint
andbinary.ReadVarint
currently returnio.EOF
when they encounter an EOF halfway to reading a varint.This:
if err != nil { return err }
pattern. In this case, they'll return an EOF which usually signals "we're done", not "we read some bad data".EOF documentation:
ErrUnexpectedEOF documentation:
Unfortunately, as pointed out by @ianlancetaylor, fixing this would technically be an API-breaking change.
The text was updated successfully, but these errors were encountered: