diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-01-18 10:54:19 +0100 |
---|---|---|
committer | André Klitzing <aklitzing@gmail.com> | 2017-02-20 13:13:08 +0000 |
commit | 152e927d0883df98eef622b9631a26cdec4fdf7e (patch) | |
tree | 3c263c92f4b38a50a56079234997978523d5f288 | |
parent | ca46a6d8f09b4a256f8017d0fdb32aa502331cc7 (diff) |
PNG image handler: Avoid "invalid distance too far back" error
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>
(cherry picked from commit 33ebe6009872229ceca4171e7e6934f919affc1f)
-rw-r--r-- | src/gui/image/qpnghandler.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/gui/image/qpnghandler.cpp b/src/gui/image/qpnghandler.cpp index e9944e1750..e84a6b4ce7 100644 --- a/src/gui/image/qpnghandler.cpp +++ b/src/gui/image/qpnghandler.cpp @@ -525,6 +525,12 @@ bool Q_INTERNAL_WIN_NO_THROW 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); |