2
1
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:
m-holger 2024-09-17 11:09:19 +01:00
parent ff2a78f579
commit 06a2d955fc
2 changed files with 11 additions and 8 deletions

View File

@ -469,14 +469,15 @@ QPDFParser::fixMissingKeys()
bool bool
QPDFParser::tooManyBadTokens() QPDFParser::tooManyBadTokens()
{ {
if (good_count <= 4) { if (--max_bad_count > 0 && good_count > 4) {
good_count = 0;
bad_count = 1;
return false;
}
if (++bad_count > 5) { if (++bad_count > 5) {
warn("too many errors; giving up on reading object"); warn("too many errors; giving up on reading object");
return true; return true;
} }
} else {
bad_count = 1;
}
good_count = 0; good_count = 0;
return false; return false;
} }

View File

@ -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.