Skip to content

Commit

Permalink
MRF: Adjust PNG limits (#5347)
Browse files Browse the repository at this point in the history
Don't allow uncompressed PNGs to be generated.
Increase the output buffer size to avoid overflow.
  • Loading branch information
lucianpls authored Feb 18, 2022
1 parent 0cdc1fd commit 6e6aff4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frmts/mrf/PNG_band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,11 @@ CPLErr PNG_Codec::CompressPNG(buf_mgr &dst, buf_mgr &src)
#endif

// Let the quality control the compression level
// Supposedly low numbers work well too while being fast
png_set_compression_level(pngp, img.quality / 10);
// Start at level 1, level 0 means uncompressed
int zlvl = img.quality / 10;
if (0 == zlvl)
zlvl = 1;
png_set_compression_level(pngp, zlvl);

// Custom strategy for zlib, set using the band option Z_STRATEGY
if (deflate_flags & ZFLAG_SMASK)
Expand Down Expand Up @@ -359,7 +362,8 @@ PNG_Band::PNG_Band( MRFDataset *pDS, const ILImage &image,
return;
}
// PNGs can be larger than the source, especially for small page size
poDS->SetPBufferSize( image.pageSizeBytes + 100);
// If PPNG is used, the palette can take up to 2100 bytes
poDS->SetPBufferSize(static_cast<unsigned int>(1.1 * image.pageSizeBytes + 4000));
}

NAMESPACE_MRF_END

0 comments on commit 6e6aff4

Please sign in to comment.