Skip to content

Commit 3076766

Browse files
Joanna Jometa-codesync[bot]
authored andcommitted
Fix underflow in parsePublishOk
Summary: Fixes underflow in `MoQFramerParser::parsePublishOk` for T251896132 and T251915198. Reviewed By: afrind Differential Revision: D91054063 fbshipit-source-id: f1552da3a6d7aea19ee39c258c54841c50f93da2
1 parent 27dfcc2 commit 3076766

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

moxygen/MoQFramer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,10 @@ folly::Expected<PublishOk, ErrorCode> MoQFrameParser::parsePublishOk(
20302030
}
20312031

20322032
if (getDraftMajorVersion(*version_) < 15) {
2033+
if (length < 1) {
2034+
XLOG(DBG4) << "parsePublishOk: UNDERFLOW on order";
2035+
return folly::makeUnexpected(ErrorCode::PARSE_UNDERFLOW);
2036+
}
20332037
auto order = cursor.readBE<uint8_t>();
20342038
length--;
20352039
if (order > folly::to_underlying(GroupOrder::NewestFirst)) {

moxygen/test/MoQFramerTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,26 @@ TEST(MoQFramerTest, ParseServerSetupNoOfParamsUnderflow) {
975975
EXPECT_EQ(result.error(), ErrorCode::PARSE_UNDERFLOW);
976976
}
977977

978+
TEST(MoQFramerTest, ParsePublishOkOrderUnderflow) {
979+
folly::IOBufQueue writeBuf{folly::IOBufQueue::cacheChainLength()};
980+
size_t size = 0;
981+
bool error = false;
982+
983+
writeVarint(writeBuf, 1, size, error); // requestID = 1
984+
writeBuf.append("\x01", 1); // forwardFlag = 1 (true)
985+
writeBuf.append("\x80", 1); // subscriberPriority = 128
986+
// omit order byte to trigger underflow
987+
988+
auto buffer = writeBuf.move();
989+
folly::io::Cursor cursor(buffer.get());
990+
991+
MoQFrameParser parser;
992+
parser.initializeVersion(kVersionDraft14);
993+
auto result = parser.parsePublishOk(cursor, buffer->computeChainDataLength());
994+
EXPECT_TRUE(result.hasError());
995+
EXPECT_EQ(result.error(), ErrorCode::PARSE_UNDERFLOW);
996+
}
997+
978998
TEST_P(MoQFramerTest, All) {
979999
auto allMsgs = moxygen::test::writeAllMessages(writer_, GetParam());
9801000
allMsgs->coalesce();

0 commit comments

Comments
 (0)