Skip to content

Commit

Permalink
adding roaring64 to fuzzer as a step toward solving issue 662 (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemire authored Oct 1, 2024
1 parent e00fe6b commit 71576fb
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion fuzz/croaring_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "roaring/roaring.h"

int LLVMFuzzerTestOneInput(const char *data, size_t size) {
int bitmap32(const char *data, size_t size) {
// We test that deserialization never fails.
roaring_bitmap_t *bitmap =
roaring_bitmap_portable_deserialize_safe(data, size);
Expand Down Expand Up @@ -48,3 +48,44 @@ int LLVMFuzzerTestOneInput(const char *data, size_t size) {
}
return 0;
}

int bitmap64(const char *data, size_t size) {
// We test that deserialization never fails.
roaring64_bitmap_t *bitmap =
roaring64_bitmap_portable_deserialize_safe(data, size);
if (bitmap) {
// The bitmap may not be usable if it does not follow the specification.
// We can validate the bitmap we recovered to make sure it is proper.
const char *reason_failure = NULL;
if (roaring64_bitmap_internal_validate(bitmap, &reason_failure)) {
// the bitmap is ok!
uint64_t cardinality = roaring64_bitmap_get_cardinality(bitmap);

for (uint32_t i = 100; i < 1000; i++) {
if (!roaring64_bitmap_contains(bitmap, i)) {
cardinality++;
roaring64_bitmap_add(bitmap, i);
}
}
uint64_t new_cardinality = roaring64_bitmap_get_cardinality(bitmap);
if (cardinality != new_cardinality) {
printf("bug\n");
exit(1);
}
}
roaring64_bitmap_free(bitmap);
}
return 0;
}
int LLVMFuzzerTestOneInput(const char *data, size_t size) {
int r;
r = bitmap32(data, size);
if (r) {
return r;
}
r = bitmap64(data, size);
if (r) {
return r;
}
return 0;
}

0 comments on commit 71576fb

Please sign in to comment.