Repository navigation
librtmp: Bound AMF decoding depth - #118
Closed
b7216309-jpg wants to merge 2 commits into
Closed
b7216309-jpg wants to merge 2 commits into
b7216309-jpg wants to merge 2 commits into
Conversation
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, AMF_DecodeArray, AMFProp_Decode, AMF3_Decode and AMF3Prop_Decode recurse once per nested object or array, as deep as the data says. That data comes from the RTMP server (connect result, onMetaData, ...), so a few bytes per level in one message overflow the send thread's stack. Each decoder now has a static *Depth variant that carries the nesting depth and fails with -1 past AMF_MAX_DEPTH (128). The public functions keep their signatures and start at depth 0. AMF3_Decode now also fails when a property fails to decode. It logged the error and went on, moving its buffer pointer back by one byte (nRes == -1) and adding the property with an unset type; with the depth limit that would be hit on every deep AMF3 message. Fixes obs-rust#102 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
Closing in favor of #116, which was opened first with the same fix. I offered the test and the AMF3 error-path change there. |
This was referenced Oct 10, 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.
Fixes #102.
AMF_Decode,AMF_DecodeArray,AMFProp_Decode,AMF3_DecodeandAMF3Prop_Decoderecurse once per nested object or array, as deep as the data says. The data comes from the RTMP server (connect result,onMetaData, ...), so one message with a few bytes per level overflows the send thread's stack.Change
*Depthvariant that carries the nesting depth and returns -1 pastAMF_MAX_DEPTH(128). The public functions keep their signatures and start at depth 0, so no caller changes.AMF3_Decodenow fails when a property fails. Before, it logged and continued: withnRes == -1it moved its buffer pointer back one byte, and it added the property with an unsetp_type. With the depth limit that path would be hit on every deeply nested AMF3 message.Tests
New
test/cmocka/test_amf.c(builds onlyamf.candlog.c,NO_CRYPTO, liketest_flv_mux):The test commit comes first. I ran it locally (MSVC, with a minimal cmocka stand-in): against the old
amf.c, 129 levels decode (900 != -1) and the deep cases crash with a stack overflow (0xC00000FD); with the fix all three tests pass. CI is the first build with the real cmocka and CMake.🤖 Generated with Claude Code