Add fuzz targets for BER/DER parsing and the Any conversion surface - #144
Open
dzatona wants to merge 2 commits into
Open
Add fuzz targets for BER/DER parsing and the Any conversion surface#144dzatona wants to merge 2 commits into
dzatona wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The README lists fuzzing among the crate's goals, but there is no fuzzing setup
in the tree. This adds a
fuzz/directory with four cargo-fuzz targets, laid outthe same way as der-parser and x509-parser. Nothing under
src/is touched.Warning
On current
master, three of the four targets crash within seconds — theyreproduce already-reported parser defects.
parse_ber_anyandparse_der_anyland on theREALdecoding defect in#143, which a 12-byte BER-valid input reaches on its own;
parse_collectionslands on the
CheckDerConstraints for boolout-of-bounds index in #142, whicha two-byte input reaches.
der_is_ber_subsetis unaffected. To keep going pastthe first artifact instead of stopping there, run with
-fork=1 -ignore_crashes=1.The targets:
parse_ber_any—Any::from_ber, then all 43Any::as_*conversions, thenone level down through
parse_content_ber.parse_der_any— the DER counterpart, plus content decoded throughDerParser::from_der_contentfor each concrete type. Separate from the BERone because DER's canonicality checks reach different code and want their own
corpus.
der_is_ber_subset— a differential check rather than a panic hunt: anythingthat parses as DER must also parse as BER, to the same header, content and
remainder. Separate so the others can be taken without also buying into that
invariant.
parse_collections—SequenceOf<T>,SetOf<T>,Vec<T>,HashSet<T>,BTreeSet<T>,AnyIteratorin both modes, and the parsers emitted byDerSequence,BerSequence,DerSet,BerParserSequenceandDerParserSequence, nested andOPTIONALfields included.parse_collectionsis a second commit, both because it is the larger half of thediff and because of what it covers: the compatibility route
FromDer→check_constraints→TryFrom<Any>. The other three reach concrete types onlythrough
Any::as_*and<T as DerParser>::from_der_content, and neither ofthose calls
CheckDerConstraints, so everycheck_constraintsimpl in the cratewas unreachable from the rest of the set — a gap in shape rather than in depth.
As its own commit it is also easy to review, or drop, separately.
Running:
No corpus is committed; I can add a seed script if that would help. Build,
fmt,clippyand the crate's own test suite are clean, and the fuzz crate stays outof the normal build.
Two choices for review:
fuzz/Cargo.lockis committed — pinning it makes a crash reproducible later,but neither der-parser nor x509-parser keeps one. I can omit it if you prefer.
would catch harness rot; I can add
.github/workflows/fuzz.ymlif you want it.