summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 16:16:08 +0000
committeracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 16:16:08 +0000
commitbf36fe526209a41c15f6747ffc1392206338896c (patch)
tree73f6ff4aacfe85a220c3fc0020a388511cfed6b6
parentd9c086a083b1a93e96d7f351bfa56ed7876ba35e (diff)
downloadchromium_src-bf36fe526209a41c15f6747ffc1392206338896c.zip
chromium_src-bf36fe526209a41c15f6747ffc1392206338896c.tar.gz
chromium_src-bf36fe526209a41c15f6747ffc1392206338896c.tar.bz2
Add support for zero-padded strings to WebMParser.
BUG=227416 TEST=WebMParserTest.ZeroPaddedStrings Review URL: https://codereview.chromium.org/14299005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194607 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/webm/webm_parser.cc4
-rw-r--r--media/webm/webm_parser_unittest.cc25
2 files changed, 28 insertions, 1 deletions
diff --git a/media/webm/webm_parser.cc b/media/webm/webm_parser.cc
index 9952efa..fb9f899 100644
--- a/media/webm/webm_parser.cc
+++ b/media/webm/webm_parser.cc
@@ -599,7 +599,9 @@ static int ParseBinary(const uint8* buf, int size, int id,
static int ParseString(const uint8* buf, int size, int id,
WebMParserClient* client) {
- std::string str(reinterpret_cast<const char*>(buf), size);
+ const uint8* end = static_cast<const uint8*>(memchr(buf, '\0', size));
+ int length = (end != NULL) ? static_cast<int>(end - buf) : size;
+ std::string str(reinterpret_cast<const char*>(buf), length);
return client->OnString(id, str) ? size : -1;
}
diff --git a/media/webm/webm_parser_unittest.cc b/media/webm/webm_parser_unittest.cc
index 4c140a6..43ad3c2 100644
--- a/media/webm/webm_parser_unittest.cc
+++ b/media/webm/webm_parser_unittest.cc
@@ -367,4 +367,29 @@ TEST_F(WebMParserTest, ReservedSizes) {
}
}
+TEST_F(WebMParserTest, ZeroPaddedStrings) {
+ const uint8 kBuffer[] = {
+ 0x1A, 0x45, 0xDF, 0xA3, 0x91, // EBMLHEADER (size = 17)
+ 0x42, 0x82, 0x80, // DocType (size = 0)
+ 0x42, 0x82, 0x81, 0x00, // DocType (size = 1) ""
+ 0x42, 0x82, 0x81, 'a', // DocType (size = 1) "a"
+ 0x42, 0x82, 0x83, 'a', 0x00, 0x00 // DocType (size = 3) "a"
+ };
+ int size = sizeof(kBuffer);
+
+ InSequence s;
+ EXPECT_CALL(client_, OnListStart(kWebMIdEBMLHeader))
+ .WillOnce(Return(&client_));
+ EXPECT_CALL(client_, OnString(kWebMIdDocType, "")).WillOnce(Return(true));
+ EXPECT_CALL(client_, OnString(kWebMIdDocType, "")).WillOnce(Return(true));
+ EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true));
+ EXPECT_CALL(client_, OnString(kWebMIdDocType, "a")).WillOnce(Return(true));
+ EXPECT_CALL(client_, OnListEnd(kWebMIdEBMLHeader)).WillOnce(Return(true));
+
+ WebMListParser parser(kWebMIdEBMLHeader, &client_);
+ int result = parser.Parse(kBuffer, size);
+ EXPECT_EQ(size, result);
+ EXPECT_TRUE(parser.IsParsingComplete());
+}
+
} // namespace media