From ba7db3028bc5173fec422fec91825c5a60b33ef5 Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 7 Feb 2020 12:55:49 -0600 Subject: [PATCH] sanity-check: check whether containers are flagged as mapped before mapping In the old unmarshal code, the decision to mark a thing as mapped (always yes) happens separately from setting the mapping. What if this could ever somehow possibly go wrong? Let's sanity-check that to be extra careful. --- roaring/unmarshal_binary.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/roaring/unmarshal_binary.go b/roaring/unmarshal_binary.go index e80e834cf..208c15d53 100644 --- a/roaring/unmarshal_binary.go +++ b/roaring/unmarshal_binary.go @@ -88,7 +88,12 @@ func readOffsets(b *Bitmap, data []byte, pos int, keyN uint32) error { // Map byte slice directly to the container data. citer.Next() - _, c := citer.Value() + k, c := citer.Value() + if !c.Mapped() { + fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n", + k, i, keyN) + c.setMapped(true) + } switch c.typ() { case containerArray: c.setArray((*[0xFFFFFFF]uint16)(unsafe.Pointer(&data[offset]))[:c.N():c.N()]) @@ -108,7 +113,12 @@ func readWithRuns(b *Bitmap, data []byte, pos int, keyN uint32) error { citer, _ := b.Containers.Iterator(0) for i := 0; i < int(keyN); i++ { citer.Next() - _, c := citer.Value() + k, c := citer.Value() + if !c.Mapped() { + fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n", + k, i, keyN) + c.setMapped(true) + } switch c.typ() { case containerRun: runCount := binary.LittleEndian.Uint16(data[pos : pos+runCountHeaderSize]) @@ -176,12 +186,17 @@ func (b *Bitmap) unmarshalPilosaRoaring(data []byte) error { // Map byte slice directly to the container data. citer.Next() - _, c := citer.Value() + k, c := citer.Value() // this shouldn't happen, since we don't normally store nils. if c == nil { continue } + if !c.Mapped() { + fmt.Printf("inexplicable: container %d (%d/%d) doesn't think it's mapped. fixing that.\n", + k, i, keyN) + c.setMapped(true) + } switch c.typ() { case containerRun: runCount := binary.LittleEndian.Uint16(data[offset : offset+runCountHeaderSize])