Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/brpc/amf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static bool ReadAMFObjectField(AMFInputStream* stream,
LOG(ERROR) << marker2str(marker) << " is not supported yet";
return false;
case AMF_MARKER_OBJECT_END:
CHECK(false) << "object-end shouldn't be present here";
LOG(ERROR) << "Unexpected object-end marker in a value position";
return false;
case AMF_MARKER_LONG_STRING: {
std::string val;
Expand Down Expand Up @@ -760,8 +760,8 @@ static bool ReadAMFObjectField(AMFInputStream* stream,
LOG(ERROR) << marker2str(marker) << " is not supported yet";
return false;
case AMF_MARKER_OBJECT_END:
CHECK(false) << "object-end shouldn't be present here";
break;
LOG(ERROR) << "Unexpected object-end marker in a value position";
return false;
case AMF_MARKER_LONG_STRING: {
std::string val;
if (!ReadAMFLongStringBody(&val, stream)) {
Expand Down Expand Up @@ -921,8 +921,8 @@ static bool ReadAMFArrayItem(AMFInputStream* stream, AMFArray* arr, int depth) {
LOG(ERROR) << marker2str(marker) << " is not supported yet";
return false;
case AMF_MARKER_OBJECT_END:
CHECK(false) << "object-end shouldn't be present here";
break;
LOG(ERROR) << "Unexpected object-end marker in a value position";
return false;
case AMF_MARKER_LONG_STRING: {
std::string val;
if (!ReadAMFLongStringBody(&val, stream)) {
Expand Down
43 changes: 43 additions & 0 deletions test/brpc_rtmp_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,49 @@ TEST(RtmpTest, amf_rejects_oversized_strict_array_count) {
EXPECT_EQ(0u, arr.size());
}

TEST(RtmpTest, amf_rejects_stray_object_end_marker) {
// A stray object-end marker (0x09) in a value position used to hit
// CHECK(false): the process aborted with -crash_on_fatal_log, and the
// object/array readers then continued as if the input were valid.
{
// As the value of a field in a generic object.
std::string req_buf;
AppendAMFObjectHeader(&req_buf);
AppendAMFShortStringBody(&req_buf, "a");
req_buf.push_back((char)brpc::AMF_MARKER_OBJECT_END);
AppendAMFObjectEnd(&req_buf);

google::protobuf::io::ArrayInputStream zc_stream(req_buf.data(), req_buf.size());
brpc::AMFInputStream istream(&zc_stream);
brpc::AMFObject obj;
EXPECT_FALSE(brpc::ReadAMFObject(&obj, &istream));
}
{
// As an item of a strict array.
std::string req_buf;
AppendAMFStrictArrayHeader(&req_buf, 1);
req_buf.push_back((char)brpc::AMF_MARKER_OBJECT_END);

google::protobuf::io::ArrayInputStream zc_stream(req_buf.data(), req_buf.size());
brpc::AMFInputStream istream(&zc_stream);
brpc::AMFArray arr;
EXPECT_FALSE(brpc::ReadAMFArray(&arr, &istream));
}
{
// As the value of a field mapped to a protobuf message.
std::string req_buf;
AppendAMFObjectHeader(&req_buf);
AppendAMFShortStringBody(&req_buf, "code");
req_buf.push_back((char)brpc::AMF_MARKER_OBJECT_END);
AppendAMFObjectEnd(&req_buf);

google::protobuf::io::ArrayInputStream zc_stream(req_buf.data(), req_buf.size());
brpc::AMFInputStream istream(&zc_stream);
brpc::RtmpInfo info;
EXPECT_FALSE(brpc::ReadAMFObject(&info, &istream));
}
}

TEST(RtmpTest, amf_rejects_deep_nested_arrays) {
ScopedAMFMaxDepth scoped_depth(4);

Expand Down
Loading