proof: Bound deserialize against wire-length OOM - #143
Open
nervana21 wants to merge 1 commit into
Open
Conversation
Davidson-Souza
requested changes
Jul 28, 2026
Collaborator
|
I thought about this a little more. Ideally this library won't use Bitcoin specific values — we do have other consumers that aren't doing the default Bitcoin stuff we do in Floresta. Floresta doesn't even use this deserializer internally. I like the patch, but I would just pick a big number — like 4GB — and stick with it, rather than computing Bitcoin-specific upper bounds. Edit: and probably make this explicit in the docs. |
Check target and hash counts before Vec::with_capacity so a hostile wire prefix cannot force a huge reservation and OOM the process.
Author
|
Updates:
|
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.
Description and Notes
Proof::deserializepreviously used untrustedu64length prefixes to sizeVec::with_capacityfor targets and hashes. A hostile payload could claim a huge count and OOM the process before any proof bytes were validated.This PR rejects oversized prefixes before allocation. Target and hash counts above
MAX_PROOF_DESERIALIZE_COUNT((4 * 1024³) / 32 == 1 << 27, ~4 GiB of 32-byte hashes) returnProofError::OversizedAllocation. Cap is deserialize-only.Proof::serializeand in-memory construction are unchanged.Changelog
To verify changes
cargo test test_deserialize_rejectscargo test --lib