diff --git a/README.md b/README.md index f6705dfe..ce9185a7 100644 --- a/README.md +++ b/README.md @@ -249,15 +249,20 @@ consider the following sample of code: buf := new(bytes.Buffer) size,err:=rb.WriteTo(buf) if err != nil { - t.Errorf("Failed writing") + fmt.Println("Failed writing") // return or panic } newrb:= New() size,err=newrb.ReadFrom(buf) if err != nil { - t.Errorf("Failed reading") + fmt.Println("Failed reading") // return or panic + } + // if buf is an untrusted source, you should validate the result + // (this adds a bit of complexity but it is necessary for security) + if newrb.Validate() != nil { + fmt.Println("Failed validation") // return or panic } if ! rb.Equals(newrb) { - t.Errorf("Cannot retrieve serialized version") + fmt.Println("Cannot retrieve serialized version") } ``` diff --git a/example_roaring_test.go b/example_roaring_test.go index b5161213..0800a959 100644 --- a/example_roaring_test.go +++ b/example_roaring_test.go @@ -58,7 +58,11 @@ func TestExample_roaring060(t *testing.T) { if err != nil { fmt.Println("Failed reading") t.Errorf("Failed reading") - + } + // if buf is an untrusted source, you should validate the result + // (this adds a bit of complexity but it is necessary for security) + if newrb.Validate() != nil { + fmt.Println("Failed validation") } if !rb1.Equals(newrb) { fmt.Println("I did not get back to original bitmap?")