-
-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overreading with v1.3.1 #108
Comments
You should add regression tests. Here is a template:
You can also add some fixed content to the bf itself. |
@klauspost Would you kindly produce a pull request ? |
@lemire With the tests? |
You have identified a bug in the |
Here is the function, can you point at the bug please? // ReadFrom reads a BitSet from a stream written using WriteTo
func (b *BitSet) ReadFrom(stream io.Reader) (int64, error) {
var length uint64
// Read length first
err := binary.Read(stream, binaryOrder, &length)
if err != nil {
return 0, err
}
newset := New(uint(length))
if uint64(newset.length) != length {
return 0, errors.New("unmarshalling error: type mismatch")
}
// Read remaining bytes as set
// current implementation bufio.Reader is more memory efficient than
// binary.Read for large set
reader := bufio.NewReader(stream)
var item = make([]byte, binary.Size(uint64(0))) // one uint64
nWords := uint64(wordsNeeded(uint(length)))
for i := uint64(0); i < nWords; i++ {
if _, err := reader.Read(item); err != nil {
return 0, err
}
newset.set[i] = binaryOrder.Uint64(item)
}
*b = *newset
return int64(b.BinaryStorageSize()), nil
} |
Bug is using |
Thanks. |
`bufio.NewReader` usually reads ahead. Limit the input to the expected size. Return `io.ErrUnexpectedEOF` when stream is unexpectedly truncated. Add regression tests (and apparently some Go 1.19 formatting) Fixes bits-and-blooms#108
Global Endianness switch. oh, wow. |
Anyway PR sent in #109 |
It seems you are still over-reading with the latest release. Here is a reproducer test:
Works with v1.2.0, but outputs:
You can extend it for more sizes.
The text was updated successfully, but these errors were encountered: