Commit 598268f6ade9fef4e18af211e77eb4e28c1ce2dc
Committed by
m-holger
1 parent
65bd8bc5
Add setMaxWarnings rather than using conditional compilation
Showing
4 changed files
with
25 additions
and
5 deletions
ChangeLog
| 1 | +2024-07-02 Jay Berkenbilt <ejb@ql.org> | ||
| 2 | + | ||
| 3 | + * Add QPDF::setMaxWarnings to set the maximum of warnings before | ||
| 4 | + warning suppression. | ||
| 5 | + | ||
| 6 | + * Add additional options to Pl_DCT construction to limit sizes and | ||
| 7 | + memory usage of compression. These are generally exposed but are | ||
| 8 | + primarily intended to support fuzz tests, which have explicit | ||
| 9 | + memory limits that are smaller than what is commonly seen in the | ||
| 10 | + wild with PDF files. | ||
| 11 | + | ||
| 1 | 2024-06-07 Jay Berkenbilt <ejb@ql.org> | 12 | 2024-06-07 Jay Berkenbilt <ejb@ql.org> |
| 2 | 13 | ||
| 3 | * 11.9.1: release | 14 | * 11.9.1: release |
fuzz/qpdf_fuzzer.cc
| @@ -57,6 +57,7 @@ FuzzHelper::getQpdf() | @@ -57,6 +57,7 @@ FuzzHelper::getQpdf() | ||
| 57 | auto is = | 57 | auto is = |
| 58 | std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer)); | 58 | std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer)); |
| 59 | auto qpdf = QPDF::create(); | 59 | auto qpdf = QPDF::create(); |
| 60 | + qpdf->setMaxWarnings(20); | ||
| 60 | qpdf->processInputSource(is); | 61 | qpdf->processInputSource(is); |
| 61 | return qpdf; | 62 | return qpdf; |
| 62 | } | 63 | } |
include/qpdf/QPDF.hh
| @@ -228,6 +228,10 @@ class QPDF | @@ -228,6 +228,10 @@ class QPDF | ||
| 228 | QPDF_DLL | 228 | QPDF_DLL |
| 229 | void setSuppressWarnings(bool); | 229 | void setSuppressWarnings(bool); |
| 230 | 230 | ||
| 231 | + // Set the maximum number of warnings to output. Subsequent warnings are suppressed. | ||
| 232 | + QPDF_DLL | ||
| 233 | + void setMaxWarnings(int); | ||
| 234 | + | ||
| 231 | // By default, QPDF will try to recover if it finds certain types of errors in PDF files. If | 235 | // By default, QPDF will try to recover if it finds certain types of errors in PDF files. If |
| 232 | // turned off, it will throw an exception on the first such problem it finds without attempting | 236 | // turned off, it will throw an exception on the first such problem it finds without attempting |
| 233 | // recovery. | 237 | // recovery. |
| @@ -1497,6 +1501,7 @@ class QPDF | @@ -1497,6 +1501,7 @@ class QPDF | ||
| 1497 | bool provided_password_is_hex_key{false}; | 1501 | bool provided_password_is_hex_key{false}; |
| 1498 | bool ignore_xref_streams{false}; | 1502 | bool ignore_xref_streams{false}; |
| 1499 | bool suppress_warnings{false}; | 1503 | bool suppress_warnings{false}; |
| 1504 | + int max_warnings{0}; | ||
| 1500 | bool attempt_recovery{true}; | 1505 | bool attempt_recovery{true}; |
| 1501 | bool check_mode{false}; | 1506 | bool check_mode{false}; |
| 1502 | std::shared_ptr<EncryptionParameters> encp; | 1507 | std::shared_ptr<EncryptionParameters> encp; |
libqpdf/QPDF.cc
| @@ -332,6 +332,12 @@ QPDF::setSuppressWarnings(bool val) | @@ -332,6 +332,12 @@ QPDF::setSuppressWarnings(bool val) | ||
| 332 | } | 332 | } |
| 333 | 333 | ||
| 334 | void | 334 | void |
| 335 | +QPDF::setMaxWarnings(int val) | ||
| 336 | +{ | ||
| 337 | + m->suppress_warnings = val; | ||
| 338 | +} | ||
| 339 | + | ||
| 340 | +void | ||
| 335 | QPDF::setAttemptRecovery(bool val) | 341 | QPDF::setAttemptRecovery(bool val) |
| 336 | { | 342 | { |
| 337 | m->attempt_recovery = val; | 343 | m->attempt_recovery = val; |
| @@ -500,14 +506,11 @@ QPDF::warn(QPDFExc const& e) | @@ -500,14 +506,11 @@ QPDF::warn(QPDFExc const& e) | ||
| 500 | { | 506 | { |
| 501 | m->warnings.push_back(e); | 507 | m->warnings.push_back(e); |
| 502 | if (!m->suppress_warnings) { | 508 | if (!m->suppress_warnings) { |
| 503 | -// QXXXQ | ||
| 504 | -#ifdef QPDF_OSS_FUZZ | ||
| 505 | - if (m->warnings.size() > 20) { | ||
| 506 | - *m->log->getWarn() << "WARNING: too many warnings - additional warnings surpressed\n"; | 509 | + if (m->max_warnings > 0 && m->warnings.size() > 20) { |
| 510 | + *m->log->getWarn() << "WARNING: too many warnings - additional warnings suppressed\n"; | ||
| 507 | m->suppress_warnings = true; | 511 | m->suppress_warnings = true; |
| 508 | return; | 512 | return; |
| 509 | } | 513 | } |
| 510 | -#endif | ||
| 511 | *m->log->getWarn() << "WARNING: " << m->warnings.back().what() << "\n"; | 514 | *m->log->getWarn() << "WARNING: " << m->warnings.back().what() << "\n"; |
| 512 | } | 515 | } |
| 513 | } | 516 | } |