Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 0bc4ce7

Browse files
crowelljeffkaufman
authored andcommitted
Fix two off-by-one reads in the CSS parser.
Fixes #1276 (Squash of 5ac1322, c936eaa, 6dfaf07, and 356a845)
1 parent 7cccc26 commit 0bc4ce7

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

‎third_party/css_parser/src/webutil/css/parser.cc‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929

3030
#include "base/logging.h"
3131
#include "base/macros.h"
32-
#include "base/scoped_ptr.h"
3332
#include "strings/strutil.h"
3433
#include "third_party/utf/utf.h"
3534
#include "util/gtl/stl_util.h"
3635
#include "util/utf8/public/unicodetext.h"
3736
#include "util/utf8/public/unilib.h"
38-
#include "webutil/css/fallthrough_intended.h"
39-
#include "webutil/css/string.h"
37+
#include "webutil/css/fallthrough_intended.h" // Needed in open source
4038
#include "webutil/css/string_util.h"
4139
#include "webutil/css/util.h"
4240
#include "webutil/css/value.h"
@@ -542,7 +540,7 @@ char32 Parser::ParseEscape() {
542540
}
543541
if (end_ - in_ >= 2 && memcmp(in_, "\r\n", 2) == 0)
544542
in_ += 2;
545-
else if (IsSpace(*in_))
543+
else if (in_ < end_ && IsSpace(*in_))
546544
in_++;
547545
}
548546

@@ -926,7 +924,6 @@ Value* Parser::ParseUrl() {
926924
if (len && rune != Runeerror) {
927925
s.push_back(rune);
928926
in_ += len;
929-
DCHECK(!Done());
930927
} else {
931928
ReportParsingError(kUtf8Error, "UTF8 parsing error in URL");
932929
in_++;
@@ -2387,7 +2384,9 @@ MediaQuery* Parser::ParseMediaQuery() {
23872384
found_and = true;
23882385
}
23892386
} else {
2390-
if (ident.empty()) {
2387+
if (in_ >= end_) {
2388+
ReportParsingError(kMediaError, "Unexpected EOF");
2389+
} else if (ident.empty()) {
23912390
ReportParsingError(kMediaError, StringPrintf(
23922391
"Unexpected char in media query: %c", *in_));
23932392
} else {

‎third_party/css_parser/src/webutil/css/parser_unittest.cc‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,4 +2696,18 @@ TEST_F(ParserTest, ParseAnyParens) {
26962696
EXPECT_STREQ(" 9 7)", p->in_);
26972697
}
26982698

2699+
TEST_F(ParserTest, BadPartialImport) {
2700+
const char kBadPartialImport[] = "@import url(R\xd5\x9b";
2701+
Parser parser(kBadPartialImport);
2702+
delete parser.ParseStylesheet();
2703+
EXPECT_NE(Parser::kNoError, parser.errors_seen_mask());
2704+
}
2705+
2706+
TEST_F(ParserTest, BadPartialImportEncoding) {
2707+
const char kBadPartialImportEncoding[] = "@import url(R\xd5";
2708+
Parser parser(kBadPartialImportEncoding);
2709+
delete parser.ParseStylesheet();
2710+
EXPECT_NE(Parser::kNoError, parser.errors_seen_mask());
2711+
}
2712+
26992713
} // namespace Css

0 commit comments

Comments
 (0)