Skip to content

Fix AMF0 value readers that leave part of a value unread - #3674

Open
sjawhar wants to merge 1 commit into
apache:masterfrom
sjawhar:pr-a4
Open

sjawhar wants to merge 1 commit into
apache:masterfrom
sjawhar:pr-a4

Conversation

@sjawhar

@sjawhar sjawhar commented Oct 26, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: none

Problem Summary: AMF0 defines the markers 0x00 to 0x11. A larger marker falls out of the value switches in both ReadAMFObjectField functions and in ReadAMFArrayItem. The functions then return true without reading a value, and the next bytes are read as the next field or item. #3597 fixed this for a stray object-end marker. Two more cases leave bytes unread: an unreadable typed-object class name, and an object value for a protobuf field that is not a message.

What is changed and the side effects?

Changed:

  • The three switches reject an undefined marker, an unreadable class name is an error, and an object value for a non-message field is skipped.
  • reject stray AMF0 object-end marker in amf value readers #3597's test becomes RtmpTest.amf_rejects_invalid_value, and RtmpTest.amf_skips_object_value_of_non_message_field is new. Both fail on master.

Side effects:

  • Performance effects: none.

  • Breaking backward compatibility: an undefined marker or an unreadable class name is now rejected.

Tested: brpc_rtmp_unittest passes (33 tests), clang 20.


Check List:

AMF0 defines the type markers 0x00 to 0x11. A larger marker falls out
of the switches in ReadAMFObjectField and ReadAMFArrayItem, and the
readers return true without reading a value. The bytes after the
marker are parsed next, and the document is accepted if they happen
to parse. apache#3597 fixed the same problem for a stray object-end marker.
Reject the marker, as the unsupported-marker cases in the same
switches do. Switch on the raw byte, so that the new default case
does not depend on converting an undefined marker to AMFMarker. The
"marker=" logs in the object readers now print the byte as a number,
not as a character.

Two more cases in these switches leave bytes unread. The class name of a
typed object can be unreadable, for example when it is longer than a
lowered amf_max_string_size. The readers then only log, and the class
name is parsed as the object's fields. Return false, as the string cases
do. In the protobuf reader, an object value for a field that is not a
message is not read. Its fields are parsed as fields of the outer
object, and its end marker ends the outer object. Skip it, as the reader
does for an unknown field.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant