[fbreader] Improved handling of broken CSS input

Particularly, curly brackets in inline CSS would make the parser crash.
Generally, it's better to stop parsing than crash when we get into an
unexpected state.
This commit is contained in:
Slava Monich 2017-01-20 00:39:24 +02:00
parent b96b822474
commit 83ca0db6bb

View file

@ -1,6 +1,6 @@
/*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2015 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2015-2017 Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -90,7 +90,7 @@ void StyleSheetParser::parse(ZLInputStream &stream) {
void StyleSheetParser::parse(const char *text, int len, bool final) {
const char *start = text;
const char *end = text + len;
for (const char *ptr = start; ptr != end; ++ptr) {
for (const char *ptr = start; ptr != end && !myStateStack.empty(); ++ptr) {
processChar1(*ptr);
}
}
@ -220,6 +220,9 @@ void StyleSheetParser::processChar4(char c) {
case ';':
finishAttribute();
break;
case '{':
myStateStack.push(SKIP_BLOCK_CURLY);
break;
case '}':
finishRule();
myStateStack.pop();