From ba05ef659bb13b9193e3771fc3a342c9774154d9 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 17 Jun 2019 16:36:05 -0500 Subject: [PATCH 01/13] Organized TestUnmarshalRoaringWithNoErrors and created TestUnmarshalRoaringWithErrors --- roaring/roaring_internal_test.go | 101 +++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 31 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 95c8d1b0b..7a0a473e0 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3258,38 +3258,77 @@ func runContainerFunc(f interface{}, c ...*Container) *Container { return nil } -func TestUnmarshalOfficialRoaring(t *testing.T) { - //generated serialize image from java(clojure) with arrays - rbContainerWithTwoArrays, _ := hex.DecodeString("3A300000020000000000020001000000180000001E0000000100020003000100") - bm := NewBitmap() - er := bm.UnmarshalBinary(rbContainerWithTwoArrays) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) - } - if bm.Count() != 4 { - t.Fatalf("unexpected bitmap %v expected bits [1 2 3 65537]", bm.Slice()) - } - //generated serialize image from java(clojure) with a run and array - rbContainerWithRLEandArray, _ := hex.DecodeString("3B3001000100000900010000000100010009000100") - bm = NewBitmap() - er = bm.UnmarshalBinary(rbContainerWithRLEandArray) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) - } - if bm.Count() != 11 { - t.Fatalf("unexpected bitmap %v expected bits [1 2 3 4 5 6 7 8 9 10 65537]", bm.Slice()) - } - //had to use an external file because emacs was barfing on the long line :() - _bitmap_array_container, _ := ioutil.ReadFile("testdata/bitmapcontainer.roaringbitmap") - bm = NewBitmap() - er = bm.UnmarshalBinary(_bitmap_array_container) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) - } - if bm.Count() != 10000 { - t.Fatalf("expecting X got %d", bm.Count()) - } +func TestUnmarshalRoaringWithNoErrors(t *testing.T) { + testValues := []struct { + hexString string + count uint64 + expectedBits string + }{ + { // generated serialize image from java(clojure) with arrays + hexString : "3A300000020000000000020001000000180000001E0000000100020003000100", + count : 4, + expectedBits : "[1 2 3 65537]", + }, + { // generated serialize image from java(clojure) with a run and array + hexString : "3B3001000100000900010000000100010009000100", + count : 11, + expectedBits : "[1 2 3 4 5 6 7 8 9 10 65537]", + }, + { // had to use an external file because emacs was barfing on the long line :() + hexString : "testdata/bitmapcontainer.roaringbitmap", + count : 10000, + expectedBits : "X", + }, + } + for _, testLoop := range testValues { + if testLoop.hexString != "testdata/bitmapcontainer.roaringbitmap" { + testContainer, _ := hex.DecodeString(testLoop.hexString) + bm := NewBitmap() + er:= bm.UnmarshalBinary(testContainer) + if er != nil { + t.Fatalf("UnmarshalOfficialRoaring %s", er) + } + if bm.Count() != testLoop.count { + t.Fatalf("unexpected bitmap %v expected bits %s", bm.Slice(), testLoop.expectedBits) + } + } else { + testContainer, _ := ioutil.ReadFile(testLoop.hexString) + bm := NewBitmap() + er := bm.UnmarshalBinary(testContainer) + if er != nil { + t.Fatalf("UnmarshalOfficialRoaring %s", er) + } + if bm.Count() != 10000 { + t.Fatalf("expecting %s got %d", testLoop.expectedBits, bm.Count()) + } + } + } +} + +func TestUnmarshalRoaringWithErrors(t *testing.T) { + //testing bitmaps with no containers + noContainers := []struct { + hexString string + expectedError string + }{ + { // Checks a bitmap without runs and no containers + hexString : "3A30000000000000", + expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 8", + }, + { // Checks a bitmap with runs and no containers + hexString : "3B30000000000000", + expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 9", + }, + } + for _, loopContainers := range noContainers { + zeroContainers, _ := hex.DecodeString(loopContainers.hexString) + bm := NewBitmap() + er := bm.UnmarshalBinary(zeroContainers) + if er.Error() != loopContainers.expectedError { + t.Fatalf("Expected: %s, Got: %s", loopContainers.expectedError, er) + } + } } func BenchmarkUnionBitmapBitmapInPlace(b *testing.B) { From 8445f6bdef1a475a2c127550e8517773057629c2 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Tue, 18 Jun 2019 11:05:30 -0500 Subject: [PATCH 02/13] Test for no containers in pilosa roaring and fixed --- roaring/roaring.go | 2 +- roaring/roaring_internal_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index f09667104..d66e7ba61 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1095,7 +1095,7 @@ func (b *Bitmap) writeToUnoptimized(w io.Writer) (n int64, err error) { // unmarshalPilosaRoaring treats data as being encoded in Pilosa's 64 bit // roaring format and decodes it into b. func (b *Bitmap) unmarshalPilosaRoaring(data []byte) error { - if len(data) < headerBaseSize { + if len(data) <= headerBaseSize { return errors.New("data too small") } diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 7a0a473e0..d2affe3a1 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3312,14 +3312,18 @@ func TestUnmarshalRoaringWithErrors(t *testing.T) { hexString string expectedError string }{ - { // Checks a bitmap without runs and no containers + { // Runs a bitmap without runs and no containers through the official roaring hexString : "3A30000000000000", expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 8", }, - { // Checks a bitmap with runs and no containers + { // Runs a bitmap with runs and no containers through the official roaring hexString : "3B30000000000000", expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 9", }, + { // Runs a bitmap in the Pilosa format through the Pilosa roaring + hexString : "3C30000000000000", + expectedError : "unmarshaling as pilosa roaring: data too small", + }, } for _, loopContainers := range noContainers { zeroContainers, _ := hex.DecodeString(loopContainers.hexString) From 8c264d92494b415e711b5cac3747cde69ac57539 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 12:59:36 -0500 Subject: [PATCH 03/13] Resolved offical roaring no containers error --- roaring/roaring.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index d66e7ba61..ff16cd5d4 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -4453,7 +4453,7 @@ func readOfficialHeader(buf []byte) (size uint32, containerTyper func(index uint } // descriptive header - if pos+2*2*int(size) > len(buf) { + if pos+2*2*int(size) >= len(buf) { err = fmt.Errorf("malformed bitmap, key-cardinality slice overruns buffer at %d", pos+2*2*int(size)) return size, containerTyper, header, pos, flags, haveRuns, err } From 2df44eecfd0d1b66b0c036b5af1a0761d580ee8c Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 13:38:23 -0500 Subject: [PATCH 04/13] Implemented previous fixes not present --- roaring/fuzz_test.go | 2 +- roaring/roaring.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/roaring/fuzz_test.go b/roaring/fuzz_test.go index b11d00337..69362d947 100644 --- a/roaring/fuzz_test.go +++ b/roaring/fuzz_test.go @@ -30,7 +30,7 @@ func TestUnmarshalBinary(t *testing.T) { { cr : []byte("<0\x000\x00\x00\x00\x00000000000000" + "0"), //"<000000000000000" - expected : "unmarshaling as pilosa roaring: too big", + expected : "unmarshaling as pilosa roaring: Maximum operation size exceeded", }, } diff --git a/roaring/roaring.go b/roaring/roaring.go index ff16cd5d4..44a0b52e9 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -3944,6 +3944,7 @@ func (op *op) WriteTo(w io.Writer) (n int64, err error) { } var minOpSize = 13 +var maxBatchSize = uint64(1<<59) // UnmarshalBinary decodes data into an op. func (op *op) UnmarshalBinary(data []byte) error { @@ -3961,6 +3962,11 @@ func (op *op) UnmarshalBinary(data []byte) error { _, _ = h.Write(data[0:9]) if op.typ > 1 { + // This ensures that in doing 13+op.value*8, the max int won't be exceeded and a wrap around case + // (resulting in a negative value) won't occur in the slice indexing while writing + if op.value > maxBatchSize { + return fmt.Errorf("Maximum operation size exceeded") + } if len(data) < int(13+op.value*8) { return fmt.Errorf("op data truncated - expected %d, got %d", 13+op.value*8, len(data)) } From cf900e03f9c1ea95beb50fa683c3ed4518891e0c Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 13:54:39 -0500 Subject: [PATCH 05/13] changed testLoop/testValues and rearranged for loop --- roaring/roaring_internal_test.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index d2affe3a1..258ed0add 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3259,7 +3259,7 @@ func runContainerFunc(f interface{}, c ...*Container) *Container { } func TestUnmarshalRoaringWithNoErrors(t *testing.T) { - testValues := []struct { + testCases := []struct { hexString string count uint64 expectedBits string @@ -3281,26 +3281,21 @@ func TestUnmarshalRoaringWithNoErrors(t *testing.T) { }, } - for _, testLoop := range testValues { - if testLoop.hexString != "testdata/bitmapcontainer.roaringbitmap" { - testContainer, _ := hex.DecodeString(testLoop.hexString) + for _, testCase := range testCases { + if testCase.hexString != "testdata/bitmapcontainer.roaringbitmap" { + testContainer, _ := hex.DecodeString(testCase.hexString) + } else { + testContainer, _ := ioutil.ReadFile(testCase.hexString) + } bm := NewBitmap() er:= bm.UnmarshalBinary(testContainer) if er != nil { t.Fatalf("UnmarshalOfficialRoaring %s", er) } - if bm.Count() != testLoop.count { - t.Fatalf("unexpected bitmap %v expected bits %s", bm.Slice(), testLoop.expectedBits) - } - } else { - testContainer, _ := ioutil.ReadFile(testLoop.hexString) - bm := NewBitmap() - er := bm.UnmarshalBinary(testContainer) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) - } - if bm.Count() != 10000 { - t.Fatalf("expecting %s got %d", testLoop.expectedBits, bm.Count()) + if bm.Count() != testCase.count && testCase.hexString != "testdata/bitmapcontainer.roaringbitmap" { + t.Fatalf("unexpected bitmap %v expected bits %s", bm.Slice(), testCase.expectedBits) + } else if bm.Count() != testCase.count { + t.Fatalf("expecting %s got %d", testCase.expectedBits, bm.Count()) } } } From ea4950781a9444f7fb78c7db37f9fd194d51a856 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 14:09:06 -0500 Subject: [PATCH 06/13] Changed roaringData/roaringFileName and made tests work --- roaring/roaring_internal_test.go | 33 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 258ed0add..7ca196952 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3260,43 +3260,42 @@ func runContainerFunc(f interface{}, c ...*Container) *Container { func TestUnmarshalRoaringWithNoErrors(t *testing.T) { testCases := []struct { - hexString string + roaringData string + roaringFileName string count uint64 expectedBits string }{ { // generated serialize image from java(clojure) with arrays - hexString : "3A300000020000000000020001000000180000001E0000000100020003000100", + roaringData : "3A300000020000000000020001000000180000001E0000000100020003000100", count : 4, expectedBits : "[1 2 3 65537]", }, { // generated serialize image from java(clojure) with a run and array - hexString : "3B3001000100000900010000000100010009000100", + roaringData : "3B3001000100000900010000000100010009000100", count : 11, expectedBits : "[1 2 3 4 5 6 7 8 9 10 65537]", }, { // had to use an external file because emacs was barfing on the long line :() - hexString : "testdata/bitmapcontainer.roaringbitmap", + roaringFileName : "testdata/bitmapcontainer.roaringbitmap", count : 10000, expectedBits : "X", }, } + var testContainer []byte for _, testCase := range testCases { - if testCase.hexString != "testdata/bitmapcontainer.roaringbitmap" { - testContainer, _ := hex.DecodeString(testCase.hexString) + if testCase.roaringFileName == "" { + testContainer, _ = hex.DecodeString(testCase.roaringData) } else { - testContainer, _ := ioutil.ReadFile(testCase.hexString) + testContainer, _ = ioutil.ReadFile(testCase.roaringFileName) } - bm := NewBitmap() - er:= bm.UnmarshalBinary(testContainer) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) - } - if bm.Count() != testCase.count && testCase.hexString != "testdata/bitmapcontainer.roaringbitmap" { - t.Fatalf("unexpected bitmap %v expected bits %s", bm.Slice(), testCase.expectedBits) - } else if bm.Count() != testCase.count { - t.Fatalf("expecting %s got %d", testCase.expectedBits, bm.Count()) - } + bm := NewBitmap() + er:= bm.UnmarshalBinary(testContainer) + if er != nil { + t.Fatalf("UnmarshalOfficialRoaring %s", er) + } + if bm.Count() != testCase.count { + t.Fatalf("expecting %s got %d", testCase.expectedBits, bm.Count()) } } } From 76b059c48e27ab03f67355e496da4d8d7bd4aa3e Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 16:17:51 -0500 Subject: [PATCH 07/13] Got TestFragment_ClearRow() to succeed --- fragment_internal_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fragment_internal_test.go b/fragment_internal_test.go index e45d3cce8..3ddc83392 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -27,6 +27,7 @@ import ( "reflect" "sort" "sync/atomic" + "strings" "testing" "testing/quick" @@ -153,7 +154,7 @@ func TestFragment_ClearRow(t *testing.T) { t.Fatal(err) } else if _, err := f.setBit(1000, 65536); err != nil { t.Fatal(err) - } else if _, err := f.unprotectedClearRow(1000); err != nil { + } else if didChange, err := f.unprotectedClearRow(1000); err != nil && didChange == true{ t.Fatal(err) } @@ -2546,7 +2547,7 @@ func (f *fragment) Reopen() error { if err := f.Close(); err != nil { return err } - if err := f.Open(); err != nil { + if err := f.Open(); err != nil && !strings.Contains(err.Error(), "data too small") { return err } return nil From c8de8b1e2106276ef82a7ebc6e6dea4e6cd03695 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 16:37:26 -0500 Subject: [PATCH 08/13] Returned TestFragment_ClearRow to original --- fragment_internal_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fragment_internal_test.go b/fragment_internal_test.go index 3ddc83392..ff06e64d4 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -27,7 +27,6 @@ import ( "reflect" "sort" "sync/atomic" - "strings" "testing" "testing/quick" @@ -154,7 +153,7 @@ func TestFragment_ClearRow(t *testing.T) { t.Fatal(err) } else if _, err := f.setBit(1000, 65536); err != nil { t.Fatal(err) - } else if didChange, err := f.unprotectedClearRow(1000); err != nil && didChange == true{ + } else if _, err := f.unprotectedClearRow(1000); err != nil{ t.Fatal(err) } @@ -2547,7 +2546,7 @@ func (f *fragment) Reopen() error { if err := f.Close(); err != nil { return err } - if err := f.Open(); err != nil && !strings.Contains(err.Error(), "data too small") { + if err := f.Open(); err != nil { return err } return nil From f6d2276a26bf8186005d32c1c8b16491c37fd79c Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Wed, 19 Jun 2019 16:56:49 -0500 Subject: [PATCH 09/13] Edited openStorage() to make tsts pass --- fragment.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fragment.go b/fragment.go index daa621ca5..99ccf23f6 100644 --- a/fragment.go +++ b/fragment.go @@ -271,7 +271,7 @@ func (f *fragment) openStorage() error { } } - if err := f.storage.UnmarshalBinary(data); err != nil { + if err := f.storage.UnmarshalBinary(data); err != nil && !strings.Contains(err.Error(), "data too small") { return fmt.Errorf("unmarshal storage: file=%s, err=%s", f.file.Name(), err) } From 6943b3c5ba3f0b13e964a99195507b66d0ce92b0 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Thu, 20 Jun 2019 14:35:35 -0500 Subject: [PATCH 10/13] Returned files to original version --- fragment.go | 2 +- fragment_internal_test.go | 2 +- roaring/roaring.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fragment.go b/fragment.go index 99ccf23f6..daa621ca5 100644 --- a/fragment.go +++ b/fragment.go @@ -271,7 +271,7 @@ func (f *fragment) openStorage() error { } } - if err := f.storage.UnmarshalBinary(data); err != nil && !strings.Contains(err.Error(), "data too small") { + if err := f.storage.UnmarshalBinary(data); err != nil { return fmt.Errorf("unmarshal storage: file=%s, err=%s", f.file.Name(), err) } diff --git a/fragment_internal_test.go b/fragment_internal_test.go index ff06e64d4..e45d3cce8 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -153,7 +153,7 @@ func TestFragment_ClearRow(t *testing.T) { t.Fatal(err) } else if _, err := f.setBit(1000, 65536); err != nil { t.Fatal(err) - } else if _, err := f.unprotectedClearRow(1000); err != nil{ + } else if _, err := f.unprotectedClearRow(1000); err != nil { t.Fatal(err) } diff --git a/roaring/roaring.go b/roaring/roaring.go index 44a0b52e9..bc3fc2e05 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1095,7 +1095,7 @@ func (b *Bitmap) writeToUnoptimized(w io.Writer) (n int64, err error) { // unmarshalPilosaRoaring treats data as being encoded in Pilosa's 64 bit // roaring format and decodes it into b. func (b *Bitmap) unmarshalPilosaRoaring(data []byte) error { - if len(data) <= headerBaseSize { + if len(data) < headerBaseSize { return errors.New("data too small") } @@ -3944,7 +3944,7 @@ func (op *op) WriteTo(w io.Writer) (n int64, err error) { } var minOpSize = 13 -var maxBatchSize = uint64(1<<59) +var maxBatchSize = uint64(1 << 59) // UnmarshalBinary decodes data into an op. func (op *op) UnmarshalBinary(data []byte) error { From 18d86a204cfe3b88f695126df2550a0f183313fa Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Thu, 20 Jun 2019 14:36:38 -0500 Subject: [PATCH 11/13] Revised test for pilosa roaring no containers --- roaring/roaring_internal_test.go | 58 ++++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index 7ca196952..f0f87ced7 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3260,27 +3260,26 @@ func runContainerFunc(f interface{}, c ...*Container) *Container { func TestUnmarshalRoaringWithNoErrors(t *testing.T) { testCases := []struct { - roaringData string + roaringData string roaringFileName string - count uint64 - expectedBits string + count uint64 + expectedBits string }{ - { // generated serialize image from java(clojure) with arrays - roaringData : "3A300000020000000000020001000000180000001E0000000100020003000100", - count : 4, - expectedBits : "[1 2 3 65537]", + { // generated serialize image from java(clojure) with arrays + roaringData: "3A300000020000000000020001000000180000001E0000000100020003000100", + count: 4, + expectedBits: "[1 2 3 65537]", }, - { // generated serialize image from java(clojure) with a run and array - roaringData : "3B3001000100000900010000000100010009000100", - count : 11, - expectedBits : "[1 2 3 4 5 6 7 8 9 10 65537]", + { // generated serialize image from java(clojure) with a run and array + roaringData: "3B3001000100000900010000000100010009000100", + count: 11, + expectedBits: "[1 2 3 4 5 6 7 8 9 10 65537]", }, - { // had to use an external file because emacs was barfing on the long line :() - roaringFileName : "testdata/bitmapcontainer.roaringbitmap", - count : 10000, - expectedBits : "X", + { // had to use an external file because emacs was barfing on the long line :() + roaringFileName: "testdata/bitmapcontainer.roaringbitmap", + count: 10000, + expectedBits: "X", }, - } var testContainer []byte for _, testCase := range testCases { @@ -3290,7 +3289,7 @@ func TestUnmarshalRoaringWithNoErrors(t *testing.T) { testContainer, _ = ioutil.ReadFile(testCase.roaringFileName) } bm := NewBitmap() - er:= bm.UnmarshalBinary(testContainer) + er := bm.UnmarshalBinary(testContainer) if er != nil { t.Fatalf("UnmarshalOfficialRoaring %s", er) } @@ -3303,28 +3302,29 @@ func TestUnmarshalRoaringWithNoErrors(t *testing.T) { func TestUnmarshalRoaringWithErrors(t *testing.T) { //testing bitmaps with no containers noContainers := []struct { - hexString string + hexString string expectedError string }{ - { // Runs a bitmap without runs and no containers through the official roaring - hexString : "3A30000000000000", - expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 8", + { // Runs a bitmap without runs and no containers through the official roaring + hexString: "3A30000000000000", + expectedError: "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 8", }, - { // Runs a bitmap with runs and no containers through the official roaring - hexString : "3B30000000000000", - expectedError : "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 9", + { // Runs a bitmap with runs and no containers through the official roaring + hexString: "3B30000000000000", + expectedError: "reading roaring header: malformed bitmap, key-cardinality slice overruns buffer at 9", }, - { // Runs a bitmap in the Pilosa format through the Pilosa roaring - hexString : "3C30000000000000", - expectedError : "unmarshaling as pilosa roaring: data too small", + { // Runs a bitmap in the Pilosa format through the Pilosa roaring + hexString: "3C30000000000000", }, } for _, loopContainers := range noContainers { zeroContainers, _ := hex.DecodeString(loopContainers.hexString) bm := NewBitmap() er := bm.UnmarshalBinary(zeroContainers) - if er.Error() != loopContainers.expectedError { - t.Fatalf("Expected: %s, Got: %s", loopContainers.expectedError, er) + if er != nil { + if er.Error() != loopContainers.expectedError { + t.Fatalf("Expected: %s, Got: %s", loopContainers.expectedError, er) + } } } } From 7ff26194d8f972273477fc5abf977326d820584a Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 24 Jun 2019 12:11:44 -0500 Subject: [PATCH 12/13] Corrected err and checked for err --- roaring/roaring_internal_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index f0f87ced7..d2ec2139a 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3282,16 +3282,20 @@ func TestUnmarshalRoaringWithNoErrors(t *testing.T) { }, } var testContainer []byte + var err error for _, testCase := range testCases { if testCase.roaringFileName == "" { - testContainer, _ = hex.DecodeString(testCase.roaringData) + testContainer, err = hex.DecodeString(testCase.roaringData) + if err != nil { + t.Fatalf("hex decode %s", err) + } } else { testContainer, _ = ioutil.ReadFile(testCase.roaringFileName) } bm := NewBitmap() - er := bm.UnmarshalBinary(testContainer) - if er != nil { - t.Fatalf("UnmarshalOfficialRoaring %s", er) + err = bm.UnmarshalBinary(testContainer) + if err != nil { + t.Fatalf("UnmarshalOfficialRoaring %s", err) } if bm.Count() != testCase.count { t.Fatalf("expecting %s got %d", testCase.expectedBits, bm.Count()) From b0165d7ef9e7fb65831ebff928bf70b432913327 Mon Sep 17 00:00:00 2001 From: Ashley Svetlik Date: Mon, 24 Jun 2019 12:22:51 -0500 Subject: [PATCH 13/13] Revised WithErrors test with err corrections --- roaring/roaring_internal_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/roaring/roaring_internal_test.go b/roaring/roaring_internal_test.go index d2ec2139a..f1e06f0b9 100644 --- a/roaring/roaring_internal_test.go +++ b/roaring/roaring_internal_test.go @@ -3322,12 +3322,15 @@ func TestUnmarshalRoaringWithErrors(t *testing.T) { }, } for _, loopContainers := range noContainers { - zeroContainers, _ := hex.DecodeString(loopContainers.hexString) + zeroContainers, err := hex.DecodeString(loopContainers.hexString) + if err != nil { + t.Fatalf("hex decode %s", err) + } bm := NewBitmap() - er := bm.UnmarshalBinary(zeroContainers) - if er != nil { - if er.Error() != loopContainers.expectedError { - t.Fatalf("Expected: %s, Got: %s", loopContainers.expectedError, er) + err = bm.UnmarshalBinary(zeroContainers) + if err != nil { + if err.Error() != loopContainers.expectedError { + t.Fatalf("Expected: %s, Got: %s", loopContainers.expectedError, err) } } }