Commit 650e9e8c authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[Offline Pages] Fix null deref in MHTMLParser.

This was found by ClusterFuzz, see test case in bug.

Bug: 828810
Change-Id: I68e3050023d2475917334c54b5d85b7d20565775
Reviewed-on: https://chromium-review.googlesource.com/995962Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548530}
parent b9d7693b
...@@ -221,9 +221,11 @@ MHTMLParser::MHTMLParser(scoped_refptr<const SharedBuffer> data) ...@@ -221,9 +221,11 @@ MHTMLParser::MHTMLParser(scoped_refptr<const SharedBuffer> data)
HeapVector<Member<ArchiveResource>> MHTMLParser::ParseArchive() { HeapVector<Member<ArchiveResource>> MHTMLParser::ParseArchive() {
MIMEHeader* header = MIMEHeader::ParseHeader(&line_reader_); MIMEHeader* header = MIMEHeader::ParseHeader(&line_reader_);
HeapVector<Member<ArchiveResource>> resources; HeapVector<Member<ArchiveResource>> resources;
if (!ParseArchiveWithHeader(header, resources)) if (ParseArchiveWithHeader(header, resources)) {
resources.clear();
creation_date_ = header->Date(); creation_date_ = header->Date();
} else {
resources.clear();
}
return resources; return resources;
} }
......
...@@ -390,7 +390,7 @@ TEST_F(MHTMLParserTest, DateParsing_InvalidDate) { ...@@ -390,7 +390,7 @@ TEST_F(MHTMLParserTest, DateParsing_InvalidDate) {
} }
TEST_F(MHTMLParserTest, DateParsing_ValidDate) { TEST_F(MHTMLParserTest, DateParsing_ValidDate) {
// Missing encoding is treated as binary. // Valid date is used.
const char mhtml_data[] = const char mhtml_data[] =
"From: <Saved by Blink>\r\n" "From: <Saved by Blink>\r\n"
"Subject: Test Subject\r\n" "Subject: Test Subject\r\n"
...@@ -415,4 +415,14 @@ TEST_F(MHTMLParserTest, DateParsing_ValidDate) { ...@@ -415,4 +415,14 @@ TEST_F(MHTMLParserTest, DateParsing_ValidDate) {
EXPECT_EQ(expected_time, creation_time); EXPECT_EQ(expected_time, creation_time);
} }
TEST_F(MHTMLParserTest, MissingBoundary) {
// No "boundary" parameter in the content type header means that parsing will
// be a failure and the header will be |nullptr|.
const char mhtml_data[] = "Content-Type: multipart/false\r\n";
HeapVector<Member<ArchiveResource>> resources =
ParseArchive(mhtml_data, sizeof(mhtml_data));
EXPECT_EQ(0U, resources.size());
}
} // namespace blink } // namespace blink
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