From a0d67d081cc9f2304db296bc01cb664c74345b11 Mon Sep 17 00:00:00 2001 From: Vignesh Venkatasubramanian Date: Tue, 7 Mar 2017 11:34:39 -0800 Subject: [PATCH] mkvmuxer: Fix hard-coded data size in EbmlElementSize EbmlElementSize for char* assumes that the varint encoding of payload size is always 1-byte. Fix that by using the correct number of bytes. mkvinfo of the new gold file: http://pastebin.com/ncR7DqEf Change-Id: I2d10708de77b2b8089900a8719ee3797dfb6994c --- README.libwebm | 2 +- mkvmuxer/mkvmuxerutil.cc | 2 +- testing/mkvmuxer_tests.cc | 19 +++++++++++++++++++ testing/testdata/long_tag_string.webm | Bin 0 -> 474 bytes 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 testing/testdata/long_tag_string.webm diff --git a/README.libwebm b/README.libwebm index 27321b7..3406f80 100644 --- a/README.libwebm +++ b/README.libwebm @@ -75,7 +75,7 @@ The tests rely upon the LIBWEBM_TEST_DATA_PATH environment variable to locate test input. The following example demonstrates running the muxer tests from the build directory: -$ LIBWEBM_TEST_DATA_PATH=path/to/libwebm/testing/testdata ./muxer_tests +$ LIBWEBM_TEST_DATA_PATH=path/to/libwebm/testing/testdata ./mkvmuxer_tests Note: Libwebm Googletest integration was built with googletest from https://github.com/google/googletest.git at git revision diff --git a/mkvmuxer/mkvmuxerutil.cc b/mkvmuxer/mkvmuxerutil.cc index 1ba17ac..bd98b11 100644 --- a/mkvmuxer/mkvmuxerutil.cc +++ b/mkvmuxer/mkvmuxerutil.cc @@ -288,7 +288,7 @@ uint64 EbmlElementSize(uint64 type, const char* value) { ebml_size += strlen(value); // Size of Datasize - ebml_size++; + ebml_size += GetCodedUIntSize(strlen(value)); return ebml_size; } diff --git a/testing/mkvmuxer_tests.cc b/testing/mkvmuxer_tests.cc index dabc72d..b807692 100644 --- a/testing/mkvmuxer_tests.cc +++ b/testing/mkvmuxer_tests.cc @@ -30,6 +30,7 @@ using mkvmuxer::Frame; using mkvmuxer::MkvWriter; using mkvmuxer::Segment; using mkvmuxer::SegmentInfo; +using mkvmuxer::Tag; using mkvmuxer::Track; using mkvmuxer::VideoTrack; @@ -996,6 +997,24 @@ TEST_F(MuxerTest, SetPixelWidthPixelHeight) { filename_)); } +TEST_F(MuxerTest, LongTagString) { + EXPECT_TRUE(SegmentInit(false, false, false)); + segment_.set_estimate_file_duration(false); + AddVideoTrack(); + Tag* const tag = segment_.AddTag(); + // 160 needs two bytes when varint encoded. + const std::string dummy_string(160, '0'); + tag->add_simple_tag("long_tag", dummy_string.c_str()); + + EXPECT_TRUE(segment_.AddFrame(dummy_data_, kFrameLength, kVideoTrackNumber, 0, + false)); + + segment_.Finalize(); + CloseWriter(); + + EXPECT_TRUE(CompareFiles(GetTestFilePath("long_tag_string.webm"), filename_)); +} + } // namespace test int main(int argc, char* argv[]) { diff --git a/testing/testdata/long_tag_string.webm b/testing/testdata/long_tag_string.webm new file mode 100644 index 0000000000000000000000000000000000000000..e8d665300a45b8d7d162586df521105ef3739a56 GIT binary patch literal 474 zcmb1gy}x+AQ(GgW({~{L)X3uWxsk)EsiizMDc7kT$Zc(8k_c`{XJh~Y##Ms8vrBgR z?(Pm=-6HC_GA(#bV;+Pj7P2lI$Xg5H356U^2lCGO?(PAqly}}%8oZ{7vHQ(BurWjv zAS-rhUEkQu@8sap*<#+!327$W3$B&AQ&m zSbVgRvAL14tu-t@EWqMH`-Ub)hh2?ZK+bg7UR><3IsJsgde_ArIr(|%@g<4rF6|Br X3g(@Uk7=)iUGA!