From 6f10badd5d93e4e8be5a16fa83f241c9ce9603e8 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 2 Jun 2020 13:11:29 -0700 Subject: [PATCH] Fix possible incorrect resolutions with avc3 The resolution values are uninitialized when parsing AVC decoder configuration record if it does not contain parameter sets (SPS/PPS), thus they could contain undefined values. Fixes #750. Change-Id: I6d54ec9f8740acd45a67b4b7d69031e097fbacc1 --- .../avc_decoder_configuration_record.cc | 8 ++--- .../codecs/avc_decoder_configuration_record.h | 16 +++++----- ...c_decoder_configuration_record_unittest.cc | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/packager/media/codecs/avc_decoder_configuration_record.cc b/packager/media/codecs/avc_decoder_configuration_record.cc index 1a0d7b9a66..d7463629a9 100644 --- a/packager/media/codecs/avc_decoder_configuration_record.cc +++ b/packager/media/codecs/avc_decoder_configuration_record.cc @@ -15,13 +15,9 @@ namespace shaka { namespace media { -AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord() - : version_(0), - profile_indication_(0), - profile_compatibility_(0), - avc_level_(0) {} +AVCDecoderConfigurationRecord::AVCDecoderConfigurationRecord() = default; -AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() {} +AVCDecoderConfigurationRecord::~AVCDecoderConfigurationRecord() = default; bool AVCDecoderConfigurationRecord::ParseInternal() { // See ISO 14496-15 sec 5.3.3.1.2 diff --git a/packager/media/codecs/avc_decoder_configuration_record.h b/packager/media/codecs/avc_decoder_configuration_record.h index d15a63bb67..2924cbedde 100644 --- a/packager/media/codecs/avc_decoder_configuration_record.h +++ b/packager/media/codecs/avc_decoder_configuration_record.h @@ -46,16 +46,16 @@ class AVCDecoderConfigurationRecord : public DecoderConfigurationRecord { private: bool ParseInternal() override; - uint8_t version_; - uint8_t profile_indication_; - uint8_t profile_compatibility_; - uint8_t avc_level_; + uint8_t version_ = 0; + uint8_t profile_indication_ = 0; + uint8_t profile_compatibility_ = 0; + uint8_t avc_level_ = 0; // Extracted from SPS. - uint32_t coded_width_; - uint32_t coded_height_; - uint32_t pixel_width_; - uint32_t pixel_height_; + uint32_t coded_width_ = 0; + uint32_t coded_height_ = 0; + uint32_t pixel_width_ = 0; + uint32_t pixel_height_ = 0; DISALLOW_COPY_AND_ASSIGN(AVCDecoderConfigurationRecord); }; diff --git a/packager/media/codecs/avc_decoder_configuration_record_unittest.cc b/packager/media/codecs/avc_decoder_configuration_record_unittest.cc index 635353b302..b3027d1eb7 100644 --- a/packager/media/codecs/avc_decoder_configuration_record_unittest.cc +++ b/packager/media/codecs/avc_decoder_configuration_record_unittest.cc @@ -90,6 +90,37 @@ TEST(AVCDecoderConfigurationRecordTest, SuccessWithTransferCharacteristics) { EXPECT_EQ("avc3.64001e", avc_config.GetCodecString(FOURCC_avc3)); } +TEST(AVCDecoderConfigurationRecordTest, SuccessWithNoParameterSets) { + // clang-format off + const uint8_t kAvcDecoderConfigurationData[] = { + 0x01, // version + 0x64, // profile_indication + 0x00, // profile_compatibility + 0x1E, // avc_level + 0xFF, // Least significant 3 bits is length_size_minus_one + 0xE0, // Least significant 5 bits is num_sps + 0x00, // num_pps + }; + // clang-format on + + AVCDecoderConfigurationRecord avc_config; + ASSERT_TRUE(avc_config.Parse(kAvcDecoderConfigurationData, + arraysize(kAvcDecoderConfigurationData))); + + EXPECT_EQ(1u, avc_config.version()); + EXPECT_EQ(0x64, avc_config.profile_indication()); + EXPECT_EQ(0u, avc_config.profile_compatibility()); + EXPECT_EQ(0x1E, avc_config.avc_level()); + EXPECT_EQ(4u, avc_config.nalu_length_size()); + EXPECT_EQ(0u, avc_config.coded_width()); + EXPECT_EQ(0u, avc_config.coded_height()); + EXPECT_EQ(0u, avc_config.pixel_width()); + EXPECT_EQ(0u, avc_config.pixel_height()); + EXPECT_EQ(0u, avc_config.transfer_characteristics()); + + EXPECT_EQ("avc3.64001e", avc_config.GetCodecString(FOURCC_avc3)); +} + TEST(AVCDecoderConfigurationRecordTest, FailsOnInvalidNaluLengthSize) { // clang-format off const uint8_t kAvcDecoderConfigurationData[] = {