fix(platform-wallet-ffi): bound bincode decode size on asset-lock proof bytes - #4585
Draft
Claudius-Maginificent wants to merge 1 commit into
Draft
fix(platform-wallet-ffi): bound bincode decode size on asset-lock proof bytes#4585Claudius-Maginificent wants to merge 1 commit into
Claudius-Maginificent wants to merge 1 commit into
Conversation
…of bytes `asset_lock_manager_recover` fed attacker-controlled `proof_bytes` straight into `bincode::decode_from_slice` with the unbounded `config::standard()`, so a hostile length prefix could drive an unbounded allocation across the FFI boundary (memory-exhaustion DoS). Gate `proof_len` at 16 MiB before touching the slice and hand bincode the same ceiling via `with_limit::<>`, so nested length prefixes cannot over-allocate inside the budget either. Rejection reuses the existing `ErrorInvalidParameter` code — no ABI surface change, no registry entry. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Sep 2, 2026
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.
TL;DR: Bounds the size of asset-lock proof data decoded at the platform-wallet FFI boundary, so a malicious or malformed input can't exhaust memory before it's even validated.
User story
As an app developer integrating the platform-wallet FFI, I want asset-lock proof decoding to reject oversized input up front, so a malformed or hostile proof can't stall or crash my app via unbounded memory allocation.
Scenario
Base flow
A host app passes raw asset-lock proof bytes across the FFI boundary; the FFI decodes them with
bincodebefore further processing.Actual behavior
The decode was unbounded. A crafted byte sequence — including one with an oversized internal length prefix — could make
bincodeattempt to allocate gigabytes before erroring: a memory-exhaustion DoS vector at the FFI boundary.Expected behavior
Proof bytes over 16 MiB are rejected immediately with the existing
ErrorInvalidParametercode, before any decode is attempted. Thebincodedecode itself is also bounded (with_limit::<MAX>()), so a hostile length prefix inside an otherwise-valid-sized buffer can't over-allocate either.Detailed discussion
What was done
Split out of #3968 (
rs-platform-wallet-storagePR) as part of a coordinated PR-splitting effort — see that PR's description for the full breakdown. This change is fully independent of the storage crate:packages/rs-platform-wallet-ffi/src/asset_lock/sync.rsgainsMAX_ASSET_LOCK_PROOF_SIZE_BYTES = 16 MiB, avalidate_asset_lock_proof_sizegate checked beforefrom_raw_parts, andbincode::config::standard().with_limit::<MAX>()on the decode call. Reuses the pre-existingErrorInvalidParameterFFI code — no new discriminants, no ABI surface change.Testing
New unit test asserting oversized proof bytes are rejected before decode is attempted (
cargo nextest -p platform-wallet-ffi, passes).cargo clippy -p platform-wallet-ffi --all-targetsclean.cargo fmt --checkclean.Breaking changes
None — no new error codes, no signature changes.
Checklist
Prior work
Split out of #3968 as part of a coordinated 4-PR split (PR 0 = trimmed #3968, this PR, plus two more for typed persister errors and FFI/misc fixes). See #3968 for the full rationale.
🤖 Co-authored by Claudius the Magnificent AI Agent