Open
Conversation
Author
|
For added context, this PR is needed to allow for adding |
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.
This PR adds support for the
arbitrarycrate by implementing theArbitrarytrait forBigDecimal. This enables usingBigDecimalwith fuzzing tools likecargo-fuzzandlibfuzzer, and more importantly allows to use theArbitraryderive in third party structs which include this struct as a field.A new optional feature
fuzzhas been added toCargo.toml:Note: The feature is named
fuzz(notarbitrary) to avoid a name collision with the dependency, which is required for compatibility with older Cargo versions (pre-1.60). The feature requiresstdbecause thearbitrarycrate itself does not supportno_stdImplementation Details
To prevent memory allocation failures during fuzzing, the implementation limits the generated scale to
±1,000,000. Without this limit, extremely large scale values could cause theBigDecimalto attempt allocating massive amounts of memory when converted to strings or performing certain operations.src/impl_arbitrary.rsimplementingArbitrary<'a>forBigDecimalarbitrary()- Generate a randomBigDecimalfrom unstructured dataarbitrary_take_rest()- Consume all remaining data to generate aBigDecimalsize_hint()- Provide size hints for the fuzzerUsage
Enable the feature in your
Cargo.toml:Example fuzz target:
Closes #122