Repository navigation
test(dpp): run deep value serialization tests on a large stack - #4725
Conversation
`document_batch_rejects_excessive_value_depth_during_decode` overflowed libtest's default 2 MiB per-test thread and aborted the whole `dpp` lib test binary under plain `cargo test`. The overflow is not in the decoder, which is iterative: it happens in `serialize_to_bytes()`, because `Value` derives `Encode` (and `PartialEq` and drop glue) that recurse once per nesting level, at roughly 7 KiB per level in debug builds. The sibling 256-deep round-trip test had under 12% headroom on the same budget. nextest runs each test on the 8 MiB main thread, so CI never saw it. Run both deep-value tests on a spawned thread with an explicit 16 MiB stack, re-raising any panic so assertion failures still fail the test. The depth assertions and the decode error check are unchanged. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Warning Review limit reachedNext included review available in 4 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
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 |
|
🕓 Queued for automated review — 2nd in line, estimated start in ~25 min (commit 3c66e50)
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v4.2-dev #4725 +/- ##
============================================
- Coverage 81.18% 79.34% -1.85%
============================================
Files 2827 2827
Lines 389838 396924 +7086
============================================
- Hits 316501 314945 -1556
- Misses 73337 81979 +8642
🚀 New features to boost your workflow:
|
Issue being fixed or feature implemented
On
v4.2-dev,state_transition::serialization::tests::document_batch_rejects_excessive_value_depth_during_decodeoverflows libtest's default 2 MiB per-test thread stack and aborts the entiredpplib test binary under plaincargo test:CI does not see this because the Rust job runs nextest, which executes each test in its own process on the 8 MiB main thread.
The overflow is not in the decoder. Instrumenting the test shows it aborts inside
serialize_to_bytes(), before decoding starts:Value'sDecodeandfirst_depth_exceedingare iterative, butValuestill derivesEncode,PartialEqand drop glue, which recurse once per nesting level. ARUST_MIN_STACKsweep puts the 300-deep encode between 2.0 and 2.25 MiB, roughly 7 KiB per level in debug builds. The siblingdocument_batch_value_depth_limits_align_between_decode_and_validation(256 deep, encode +PartialEq+ drop) overflows at 1.75 MiB and passes at 2 MiB, so it had under 12% headroom; lowering the failing test from 300 to 257 levels would only have bought that same thin margin.What was done?
Added a small
on_deep_value_stackhelper to the test module that runs a closure on astd::thread::Builderthread with an explicit 16 MiB stack and re-raises any panic viaresume_unwind, so assertion failures still fail the test. Both deep-value tests are wrapped in it. The 300-deep value, thefirst_data_depth_exceeding(256) == Some(257)assertion and thevalue nesting depth 257 exceeds maximum 256decode error check are unchanged; the rest of the diff is rustfmt re-indentation (git diff -wshows the real change).Swept every Rust package for fold/loop-built nested
Values: only these two tests build them recursively. Thevalidate_documentdepth tests (257 containers, no encode) pass even at a 1 MiB stack, and thers-platform-valuetests (4k to 10k deep) build their bytes by hand and only exercise iterative paths.How Has This Been Tested?
cargo test -p dpp --all-features --lib -- state_transition::serialization::tests --test-threads=1at the default stack: 21 passed (previously aborted the binary at test 13).RUST_MIN_STACK=1048576(1 MiB), so they no longer depend on the harness thread size at all.Some(257)toSome(258)reportsFAILEDwith the assertion output, confirming panic propagation from the spawned thread; reverted.cargo fmt --checkclean.Side observation, outside this PR: in debug builds, encoding a validation-passing 256-deep document costs about 1.8 MiB of stack, close to Tokio's 2 MiB worker default. Release frames are far smaller so it is not a production concern, but an iterative
EncodeforValue(mirroring the decoder) would remove the recursion entirely.Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code