Commit bf36fe52 authored by acolwell@chromium.org's avatar acolwell@chromium.org

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
parent d9c086a0
......@@ -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;
}
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment