Skip to content

Commit

Permalink
PNG image handler: Avoid "invalid distance too far back" error
Browse files Browse the repository at this point in the history
For certain slightly miscoded png images, newer versions of libpng
will trigger the mentioned zlib error and fail to read the image. This
miscoding has until now been safely ignored by all png
implementations, so such images exist in the wild, and users expect
them to work. Since the cost of the workaround is only a missed
opportunity of a tiny saving in memory usage during decoding, enable
it.

Task-number: QTBUG-58171
Change-Id: I820a9faef6d5b7af79c04404ebdceb48a096f29a
Reviewed-by: André Klitzing <aklitzing@gmail.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
  • Loading branch information
aavit committed Jan 31, 2017
1 parent 098d87c commit 33ebe60
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gui/image/qpnghandler.cpp
Expand Up @@ -521,6 +521,12 @@ bool QPngHandlerPrivate::readPngHeader()

png_set_error_fn(png_ptr, 0, 0, qt_png_warning);

#if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
// Trade off a little bit of memory for better compatibility with existing images
// Ref. "invalid distance too far back" explanation in libpng-manual.txt
png_set_option(png_ptr, PNG_MAXIMUM_INFLATE_WINDOW, PNG_OPTION_ON);
#endif

info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, 0, 0);
Expand Down

0 comments on commit 33ebe60

Please sign in to comment.