mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
In QPDFParser add a limit on total number of errors in one object
Currently, QPDFParser gives up attempting to parse an object if 5 near-consecutive bad tokens are encountered. Add a limit of a total of 15 bad tokens in a single object before giving up.
This commit is contained in:
parent
ff2a78f579
commit
06a2d955fc
@ -469,13 +469,14 @@ QPDFParser::fixMissingKeys()
|
|||||||
bool
|
bool
|
||||||
QPDFParser::tooManyBadTokens()
|
QPDFParser::tooManyBadTokens()
|
||||||
{
|
{
|
||||||
if (good_count <= 4) {
|
if (--max_bad_count > 0 && good_count > 4) {
|
||||||
if (++bad_count > 5) {
|
good_count = 0;
|
||||||
warn("too many errors; giving up on reading object");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bad_count = 1;
|
bad_count = 1;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (++bad_count > 5) {
|
||||||
|
warn("too many errors; giving up on reading object");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
good_count = 0;
|
good_count = 0;
|
||||||
return false;
|
return false;
|
||||||
|
@ -83,9 +83,11 @@ class QPDFParser
|
|||||||
std::vector<StackFrame> stack;
|
std::vector<StackFrame> stack;
|
||||||
StackFrame* frame;
|
StackFrame* frame;
|
||||||
// Number of recent bad tokens.
|
// Number of recent bad tokens.
|
||||||
int bad_count = 0;
|
int bad_count{0};
|
||||||
|
// Number of bad tokens (remaining) before giving up.
|
||||||
|
int max_bad_count{15};
|
||||||
// Number of good tokens since last bad token. Irrelevant if bad_count == 0.
|
// Number of good tokens since last bad token. Irrelevant if bad_count == 0.
|
||||||
int good_count = 0;
|
int good_count{0};
|
||||||
// Start offset including any leading whitespace.
|
// Start offset including any leading whitespace.
|
||||||
qpdf_offset_t start;
|
qpdf_offset_t start;
|
||||||
// Number of successive integer tokens.
|
// Number of successive integer tokens.
|
||||||
|
Loading…
Reference in New Issue
Block a user