2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-09 23:00:57 +00:00

Add setMaxWarnings rather than using conditional compilation

This commit is contained in:
Jay Berkenbilt 2024-07-02 09:14:21 -04:00 committed by m-holger
parent 65bd8bc57d
commit 598268f6ad
4 changed files with 25 additions and 5 deletions

View File

@ -1,3 +1,14 @@
2024-07-02 Jay Berkenbilt <ejb@ql.org>
* Add QPDF::setMaxWarnings to set the maximum of warnings before
warning suppression.
* Add additional options to Pl_DCT construction to limit sizes and
memory usage of compression. These are generally exposed but are
primarily intended to support fuzz tests, which have explicit
memory limits that are smaller than what is commonly seen in the
wild with PDF files.
2024-06-07 Jay Berkenbilt <ejb@ql.org>
* 11.9.1: release

View File

@ -57,6 +57,7 @@ FuzzHelper::getQpdf()
auto is =
std::shared_ptr<InputSource>(new BufferInputSource("fuzz input", &this->input_buffer));
auto qpdf = QPDF::create();
qpdf->setMaxWarnings(20);
qpdf->processInputSource(is);
return qpdf;
}

View File

@ -228,6 +228,10 @@ class QPDF
QPDF_DLL
void setSuppressWarnings(bool);
// Set the maximum number of warnings to output. Subsequent warnings are suppressed.
QPDF_DLL
void setMaxWarnings(int);
// By default, QPDF will try to recover if it finds certain types of errors in PDF files. If
// turned off, it will throw an exception on the first such problem it finds without attempting
// recovery.
@ -1497,6 +1501,7 @@ class QPDF
bool provided_password_is_hex_key{false};
bool ignore_xref_streams{false};
bool suppress_warnings{false};
int max_warnings{0};
bool attempt_recovery{true};
bool check_mode{false};
std::shared_ptr<EncryptionParameters> encp;

View File

@ -331,6 +331,12 @@ QPDF::setSuppressWarnings(bool val)
m->suppress_warnings = val;
}
void
QPDF::setMaxWarnings(int val)
{
m->suppress_warnings = val;
}
void
QPDF::setAttemptRecovery(bool val)
{
@ -500,14 +506,11 @@ QPDF::warn(QPDFExc const& e)
{
m->warnings.push_back(e);
if (!m->suppress_warnings) {
// QXXXQ
#ifdef QPDF_OSS_FUZZ
if (m->warnings.size() > 20) {
*m->log->getWarn() << "WARNING: too many warnings - additional warnings surpressed\n";
if (m->max_warnings > 0 && m->warnings.size() > 20) {
*m->log->getWarn() << "WARNING: too many warnings - additional warnings suppressed\n";
m->suppress_warnings = true;
return;
}
#endif
*m->log->getWarn() << "WARNING: " << m->warnings.back().what() << "\n";
}
}