Commit 598268f6ade9fef4e18af211e77eb4e28c1ce2dc

Authored by Jay Berkenbilt
Committed by m-holger
1 parent 65bd8bc5

Add setMaxWarnings rather than using conditional compilation

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 12 2024-06-07 Jay Berkenbilt <ejb@ql.org>
2 13  
3 14 * 11.9.1: release
... ...
fuzz/qpdf_fuzzer.cc
... ... @@ -57,6 +57,7 @@ FuzzHelper::getQpdf()
57 57 auto is =
58 58 std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer));
59 59 auto qpdf = QPDF::create();
  60 + qpdf->setMaxWarnings(20);
60 61 qpdf->processInputSource(is);
61 62 return qpdf;
62 63 }
... ...
include/qpdf/QPDF.hh
... ... @@ -228,6 +228,10 @@ class QPDF
228 228 QPDF_DLL
229 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 235 // By default, QPDF will try to recover if it finds certain types of errors in PDF files. If
232 236 // turned off, it will throw an exception on the first such problem it finds without attempting
233 237 // recovery.
... ... @@ -1497,6 +1501,7 @@ class QPDF
1497 1501 bool provided_password_is_hex_key{false};
1498 1502 bool ignore_xref_streams{false};
1499 1503 bool suppress_warnings{false};
  1504 + int max_warnings{0};
1500 1505 bool attempt_recovery{true};
1501 1506 bool check_mode{false};
1502 1507 std::shared_ptr<EncryptionParameters> encp;
... ...
libqpdf/QPDF.cc
... ... @@ -332,6 +332,12 @@ QPDF::setSuppressWarnings(bool val)
332 332 }
333 333  
334 334 void
  335 +QPDF::setMaxWarnings(int val)
  336 +{
  337 + m->suppress_warnings = val;
  338 +}
  339 +
  340 +void
335 341 QPDF::setAttemptRecovery(bool val)
336 342 {
337 343 m->attempt_recovery = val;
... ... @@ -500,14 +506,11 @@ QPDF::warn(QPDFExc const&amp; e)
500 506 {
501 507 m->warnings.push_back(e);
502 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 511 m->suppress_warnings = true;
508 512 return;
509 513 }
510   -#endif
511 514 *m->log->getWarn() << "WARNING: " << m->warnings.back().what() << "\n";
512 515 }
513 516 }
... ...