From b231c365399bdd2a8e6b6aef299b4191523e2fcd Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Wed, 23 Dec 2020 11:02:30 -0800 Subject: [PATCH] Properly handle SkipBytes with num_bytes as 0 Previously if there are no bytes remaining, SkipBytes(0) would fail, which results in parsing error in AACAudioSpecificConfig::ParseProgramConfigElement. Fixes #875. Change-Id: I271899a37303d0d3fa0cf1bf90f99227058b82df --- packager/media/base/bit_reader.cc | 4 ++-- packager/media/base/bit_reader_unittest.cc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packager/media/base/bit_reader.cc b/packager/media/base/bit_reader.cc index b6d0b4948b..a7b28f1c33 100644 --- a/packager/media/base/bit_reader.cc +++ b/packager/media/base/bit_reader.cc @@ -61,10 +61,10 @@ void BitReader::SkipToNextByte() { } bool BitReader::SkipBytes(size_t num_bytes) { - if (num_remaining_bits_in_curr_byte_ != 8) - return false; if (num_bytes == 0) return true; + if (num_remaining_bits_in_curr_byte_ != 8) + return false; data_ += num_bytes - 1; // One additional byte in curr_byte_. if (num_bytes > bytes_left_ + 1) diff --git a/packager/media/base/bit_reader_unittest.cc b/packager/media/base/bit_reader_unittest.cc index 8887f398fe..b1f06b1e6b 100644 --- a/packager/media/base/bit_reader_unittest.cc +++ b/packager/media/base/bit_reader_unittest.cc @@ -70,6 +70,7 @@ TEST(BitReaderTest, SkipBitsTest) { EXPECT_EQ(13, value8); EXPECT_FALSE(reader1.SkipBits(100)); EXPECT_TRUE(reader1.SkipBits(0)); + EXPECT_TRUE(reader1.SkipBytes(0)); EXPECT_FALSE(reader1.SkipBits(1)); }