Repository navigation
librtmp: Bound AMF/AMF3 decode recursion depth - #116
Conversation
|
I opened #118 for the same issue a few minutes after this one, with the same depth design. I'm closing it in favor of this PR. Two pieces from it may be useful here: 1. A test:
I ran it locally with MSVC and a minimal cmocka stand-in:
2. The AMF3 error path: b7216309-jpg@e465b53.
With a depth limit, every deeply nested AMF3 message reaches that path. With this PR, the 129-level AMF3 case logs a run of Feel free to cherry-pick either commit. |
7925b80 to
d09a5fa
Compare
|
Took the offer from #118 (old head 7925b80, replaced with --force-with-lease):
The local gate passes and is stamped. Marked ready. I left out #118's AMF3 error-path change (a failed |
|
@chriscoveries I see you moved this back to draft after my update. Is something blocking, or did you want to change the approach? The current head is green locally (RED→GREEN in Tier 2). Mark it ready again when you're happy and I'll merge once CI passes. |
d09a5fa to
8c2f0d1
Compare
|
Rebased onto master (old head d09a5fa, replaced with --force-with-lease). I also added the AMF3 error-path fix as a RED→GREEN pair, because this PR's depth limit makes it easy to reach (a review flagged it):
|
|
Thank you @zackees, and @b7216309-jpg for the depth test. Nothing is blocking, and sorry for the unexplained re-draft (context in the #115 comment). Your head Two follow-ups, each as its own PR with a RED test first, unless you'd rather we skip them:
|
Decodes nested AMF0 objects, strict arrays and ECMA arrays and AMF3 objects with librtmp's AMF_Decode, as for an RTMP server's command or metadata message: - 128 levels decode, 129 are refused - 200000 levels fail cleanly instead of overflowing the stack Both regressions fail until the next commit: 129 levels decode, and the deep cases crash with a stack overflow. Refs obs-rust#102 Co-Authored-By: Claude Opus 5.5 <[email protected]>
AMF_Decode, AMFProp_Decode, AMF_DecodeArray, AMF3_Decode and AMF3Prop_Decode recurse once per nesting level of remote-supplied AMF data with no limit, so a server (or MITM on plaintext RTMP) can overflow the thread stack with a deeply nested object/array payload. Rename the five recursive routines to *Depth variants carrying a depth counter and fail the decode with -1 past AMF_MAX_DEPTH (128). The public entry points keep their signatures and start at depth 0, so valid input decodes exactly as before. Fixes obs-rust#102 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Local-Gate: v1 tree=cbbf43405c0102f24c4d6e725931c2b3252cb0aa secs=323 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791670604,"gate":"rust/all/fmt","host":"linux-x86_64","key":"bf2730b1d4f44164686f48e55a2086784ac47009bec506b58941c3552845e023","lane":"lint","parents":["dd156060aa3761b627d9a586924e61f58529efa3"],"secs":146,"stamp":"f23ffcd4f572e9f47ee15b75c1755858","tree":"cbbf43405c0102f24c4d6e725931c2b3252cb0aa","v":1,"via":"run"} Ci-Attestation: {"at":1791670604,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"bf2730b1d4f44164686f48e55a2086784ac47009bec506b58941c3552845e023","lane":"lint","parents":["dd156060aa3761b627d9a586924e61f58529efa3"],"secs":146,"stamp":"c3cf26593eb4cdbb4b4ca81912f578f6","tree":"cbbf43405c0102f24c4d6e725931c2b3252cb0aa","v":1,"via":"run"} Ci-Attestation: {"at":1791670604,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"f785492681703c97bd84aacbe60603c5f1d5b2bdd9c04b3d9eb21f3b72718060","lane":"rust-test","parents":["dd156060aa3761b627d9a586924e61f58529efa3"],"secs":79,"stamp":"816d97669a90ec8e46f97237eef34f7b","tree":"cbbf43405c0102f24c4d6e725931c2b3252cb0aa","v":1,"via":"run"} Ci-Attestation: {"at":1791670604,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b5c5e63e1c049e3c75571f9f36da9a9ac3712432ecfd915708627fa73895a07c","lane":"tier2-linux","parents":["dd156060aa3761b627d9a586924e61f58529efa3"],"secs":96,"stamp":"5e92a41bd6d68fe7e33f23bfb76ff084","tree":"cbbf43405c0102f24c4d6e725931c2b3252cb0aa","v":1,"via":"run"}
A sealed or externalizable AMF3 member that fails to decode must fail the whole object. AMF3_Decode instead keeps the half-decoded property (with an unset p_type) and, for sealed members, steps the buffer back by the -1 it got. The depth limit in this PR returns -1 deep in the nesting, which makes that path easy to reach. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AMF3_Decode logged a failed AMF3Prop_Decode and kept going: it added the property with an unset p_type (which AMF_Reset could later act on), and for sealed members added the -1 result to pBuffer, re-parsing from one byte back. The dynamic loop did not check at all. Reset the object and return -1 in all three branches, as AMF_Decode does for AMF0. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=2675e34ba05c5319570b7eb37afe23f73b09cba1 secs=270 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791677832,"gate":"rust/all/fmt","host":"linux-x86_64","key":"5f3dbc9d36a60c29b6af45ecf530d9ac20b140a5b4fce26c51bbf9f97af84647","lane":"lint","parents":["92a86cd6728ae4f699e99e2262861d0521e5e5de"],"secs":123,"stamp":"ff4ddf4ac40a955ff34950cf518b9ed3","tree":"2675e34ba05c5319570b7eb37afe23f73b09cba1","v":1,"via":"run"} Ci-Attestation: {"at":1791677832,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"5f3dbc9d36a60c29b6af45ecf530d9ac20b140a5b4fce26c51bbf9f97af84647","lane":"lint","parents":["92a86cd6728ae4f699e99e2262861d0521e5e5de"],"secs":123,"stamp":"eb148c0718dd406ac9492d96e11a61a4","tree":"2675e34ba05c5319570b7eb37afe23f73b09cba1","v":1,"via":"run"} Ci-Attestation: {"at":1791677832,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"c264e2969035808f5e43e7bf0708865984296186c9479db69e6848fa2b20b571","lane":"rust-test","parents":["92a86cd6728ae4f699e99e2262861d0521e5e5de"],"secs":57,"stamp":"05b04fb0404a9cd24b06792a2d0755a9","tree":"2675e34ba05c5319570b7eb37afe23f73b09cba1","v":1,"via":"run"} Ci-Attestation: {"at":1791677832,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"bdeb7c993afd034bc1e848ebaef44b54e09f6acecd6d045f45cd40e7bab782d6","lane":"tier2-linux","parents":["92a86cd6728ae4f699e99e2262861d0521e5e5de"],"secs":90,"stamp":"1ce35f82d9c67ad91b1bee3001699e11","tree":"2675e34ba05c5319570b7eb37afe23f73b09cba1","v":1,"via":"run"}
|
Rebased onto master (old head 8c2f0d1, replaced with --force-with-lease). Since #168, cmocka tests live in |
8c2f0d1 to
df9ffab
Compare
AMF_Decode,AMFProp_Decode,AMF_DecodeArray,AMF3_DecodeandAMF3Prop_Decoderecurse once per nesting level of remote-supplied AMF data with no limit, so a server (or MITM on plaintext RTMP) can overflow the thread stack with a deeply nested object/array payload.The five recursive routines are renamed to
*Depthvariants carrying a depth counter and the decode fails with -1 pastAMF_MAX_DEPTH(128). Public entry points keep their signatures and start at depth 0, so valid input decodes exactly as before.Fixes #102