Add fuzzer for roaring_buffer_reader
#42
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a fuzzer based on libfuzzer for
roaring_buffer_reader. You can try it as follows (the fuzzer will run up to 60s):The intent of the fuzzer is to cover whether the custom deserialization and operations on roaring bitmaps implemented in
roaring_buffer_reader.cis safe and correct, in the sense that they compute the same results ascroaring.The fuzzer works as follows:
roaring_bitmap_portable_deserialize_safe. Stop if deserialization fails.roaring_buffer_create.croaring:roaring_buffer_get_cardinalityroaring_buffer_containsroaring_buffer_is_subsetroaring_buffer_androaring_buffer_andnotroaring_buffer_and_cardinalityroaring_buffer_or_cardinalityroaring_buffer_andnot_cardinalityroaring_buffer_xor_cardinalityroaring_buffer_jaccard_indexroaring_buffer_intersectroaring_buffer_is_emptyroaring_buffer_equalsroaring_buffer_rankroaring_buffer_minimumroaring_buffer_maximumIf you run the fuzzer, it pretty quickly finds that
roaring_buffer_trelies on the offset header from the serialized bitmap, which is not validated byroaring_bitmap_portable_deserialize_safe. This can cause the roaring buffer functions to return wrong results.Here's an example of that found by the fuzzer replicated in
psql:A proposed fix could be to not rely on the offset reader for untrusted input, but rather parse the containers instead (the
croaringlibrary always does this).If there's support for this change, as well as #40, then we can set up fuzzing as a Github Action (see https://google.github.io/clusterfuzzlite/running-clusterfuzzlite/github-actions/).