2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-02-14 09:40:22 +00:00

Rename Pl_Flate::setMemoryLimit to memory_limit and add accessor

This commit is contained in:
m-holger 2025-02-05 13:23:27 +00:00
parent a496dbe8b2
commit b0e34486fd
8 changed files with 22 additions and 14 deletions

View File

@ -111,7 +111,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -111,7 +111,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -109,7 +109,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -110,7 +110,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -87,7 +87,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -108,7 +108,7 @@ FuzzHelper::doChecks()
Pl_PNGFilter::setMemoryLimit(1'000'000); Pl_PNGFilter::setMemoryLimit(1'000'000);
Pl_RunLength::setMemoryLimit(1'000'000); Pl_RunLength::setMemoryLimit(1'000'000);
Pl_TIFFPredictor::setMemoryLimit(1'000'000); Pl_TIFFPredictor::setMemoryLimit(1'000'000);
Pl_Flate::setMemoryLimit(200'000); Pl_Flate::memory_limit(200'000);
// Do not decompress corrupt data. This may cause extended runtime within jpeglib without // Do not decompress corrupt data. This may cause extended runtime within jpeglib without
// exercising additional code paths in qpdf, and potentially causing counterproductive timeouts. // exercising additional code paths in qpdf, and potentially causing counterproductive timeouts.

View File

@ -48,7 +48,9 @@ class QPDF_DLL_CLASS Pl_Flate: public Pipeline
// Limit the memory used. // Limit the memory used.
// NB This is a static option affecting all Pl_Flate instances. // NB This is a static option affecting all Pl_Flate instances.
QPDF_DLL QPDF_DLL
static void setMemoryLimit(unsigned long long limit); static unsigned long long memory_limit();
QPDF_DLL
static void memory_limit(unsigned long long limit);
QPDF_DLL QPDF_DLL
void write(unsigned char const* data, size_t len) override; void write(unsigned char const* data, size_t len) override;

View File

@ -14,7 +14,7 @@
namespace namespace
{ {
unsigned long long memory_limit{0}; unsigned long long memory_limit_{0};
} // namespace } // namespace
int Pl_Flate::compression_level = Z_DEFAULT_COMPRESSION; int Pl_Flate::compression_level = Z_DEFAULT_COMPRESSION;
@ -80,10 +80,16 @@ Pl_Flate::~Pl_Flate() // NOLINT (modernize-use-equals-default)
// Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer // Must be explicit and not inline -- see QPDF_DLL_CLASS in README-maintainer
} }
void unsigned long long
Pl_Flate::setMemoryLimit(unsigned long long limit) Pl_Flate::memory_limit()
{ {
memory_limit = limit; return memory_limit_;
}
void
Pl_Flate::memory_limit(unsigned long long limit)
{
memory_limit_ = limit;
} }
void void
@ -197,9 +203,9 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
} }
uLong ready = QIntC::to_ulong(m->out_bufsize - zstream.avail_out); uLong ready = QIntC::to_ulong(m->out_bufsize - zstream.avail_out);
if (ready > 0) { if (ready > 0) {
if (memory_limit && m->action != a_deflate) { if (memory_limit_ && m->action != a_deflate) {
m->written += ready; m->written += ready;
if (m->written > memory_limit) { if (m->written > memory_limit_) {
throw std::runtime_error("PL_Flate memory limit exceeded"); throw std::runtime_error("PL_Flate memory limit exceeded");
} }
} }
@ -220,7 +226,7 @@ Pl_Flate::handleData(unsigned char const* data, size_t len, int flush)
void void
Pl_Flate::finish() Pl_Flate::finish()
{ {
if (m->written > memory_limit) { if (m->written > memory_limit_) {
throw std::runtime_error("PL_Flate memory limit exceeded"); throw std::runtime_error("PL_Flate memory limit exceeded");
} }
try { try {