Skip to content
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

"Could not deserialize bitmap for key #0: error in roaringArray.readFrom: did not find expected serialCookie in header" on v1.8.0 when reading a bitmap written by roaring64 #411

Closed
wjohnson-aurora opened this issue Jan 29, 2024 · 1 comment · Fixed by #412

Comments

@wjohnson-aurora
Copy link
Contributor

Per the io.Reader documentation, it is acceptable for an implementation to read 0 <= n <= len(p) bytes on each call to Read. I've found that roaring64.Bitmap.ReadFrom returns the following error when passed an io.Reader that reads less than len(p) bytes on calls to Read:

Could not deserialize bitmap for key #0: error in roaringArray.readFrom: did not find expected serialCookie in header

To replicate:

  1. Create main.go with the following contents:
package main

import (
	"bytes"
	"io"

	"github.com/RoaringBitmap/roaring/roaring64"
)

func main() {
	bitmap := roaring64.NewBitmap()
	bitmap.Add(1234)

	var bitmapBuf bytes.Buffer
	if _, err := bitmap.WriteTo(&bitmapBuf); err != nil {
		panic(err)
	}

	bitmapMinusOneReader := minusOneReader{
		reader: &bitmapBuf,
	}
	readBitmap := roaring64.NewBitmap()
	if _, err := readBitmap.ReadFrom(&bitmapMinusOneReader); err != nil {
		panic(err)
	}
}

type minusOneReader struct {
	reader io.Reader
}

func (r minusOneReader) Read(p []byte) (int, error) {
	if len(p) > 1 {
		p = p[:len(p)-1]
	}
	return r.reader.Read(p)
}
  1. Create go.mod with the following contents:
module roaring-replication

go 1.20

require github.com/RoaringBitmap/roaring v1.8.0

require (
	github.com/bits-and-blooms/bitset v1.12.0 // indirect
	github.com/mschoch/smat v0.2.0 // indirect
)
  1. Run go mod tidy
  2. Run go run main.go
  3. Observe error from ReadFrom:
panic: Could not deserialize bitmap for key #0: error in roaringArray.readFrom: did not find expected serialCookie in header

goroutine 1 [running]:
main.main()
	main.go:24 +0x12d
exit status 2
@lemire
Copy link
Member

lemire commented Jan 29, 2024

A pull request fixing this issue is invited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants