fix(platform-wallet): bound bincode decode size on asset-lock proof bytes - #4585
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>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe asset lock recovery path now rejects proofs larger than 16 MiB before decoding. Bincode decoding uses the same size limit. Tests verify acceptance at the limit and rejection above it. ChangesAsset lock proof validation
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change bounds proof validation and decoding at 16 MiB with boundary coverage, so it is mergeable after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks 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 |
# Conflicts: # packages/rs-platform-wallet-ffi/src/asset_lock/sync.rs
|
🕓 Queued for automated review — 3rd in line, estimated start in ~35 min (commit e91714f)
|
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
Summary by CodeRabbit