From 45fd740130b199a3117e18aad272a86db9733eb3 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Thu, 17 Dec 2020 20:23:03 +0000 Subject: [PATCH 1/2] webpload: prevent divide-by-zero when blending pixels Adds a test case to prevent regression - see commit 6eaf1ed --- libvips/foreign/webp2vips.c | 4 ++-- test/test-suite/helpers/helpers.py | 1 + test/test-suite/images/big-height.webp | Bin 0 -> 7222 bytes test/test-suite/test_foreign.py | 10 ++++++++-- 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test/test-suite/images/big-height.webp diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index e0e91e99..38a59807 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -260,9 +260,9 @@ blend_pixel( guint32 A, guint32 B ) guint8 aB = getA( B ); - guint8 fac = (aB * (256 - aA) + 128) >> 8; + guint8 fac = (aB * (255 - aA) + 127) >> 8; guint8 aR = aA + fac; - int scale = (1 << 24) / aR; + int scale = aR == 0 ? 0 : (1 << 24) / aR; guint8 rR = BLEND( getR( A ), aA, getR( B ), fac, scale ); guint8 gR = BLEND( getG( A ), aA, getG( B ), fac, scale ); diff --git a/test/test-suite/helpers/helpers.py b/test/test-suite/helpers/helpers.py index 8d1c309d..585a7f0c 100644 --- a/test/test-suite/helpers/helpers.py +++ b/test/test-suite/helpers/helpers.py @@ -22,6 +22,7 @@ ANALYZE_FILE = os.path.join(IMAGES, "t00740_tr1_segm.hdr") GIF_FILE = os.path.join(IMAGES, "cramps.gif") WEBP_FILE = os.path.join(IMAGES, "1.webp") WEBP_LOOKS_LIKE_SVG_FILE = os.path.join(IMAGES, "looks-like-svg.webp") +WEBP_ANIMATED_FILE = os.path.join(IMAGES, "big-height.webp") EXR_FILE = os.path.join(IMAGES, "sample.exr") FITS_FILE = os.path.join(IMAGES, "WFPC2u5780205r_c0fx.fits") OPENSLIDE_FILE = os.path.join(IMAGES, "CMU-1-Small-Region.svs") diff --git a/test/test-suite/images/big-height.webp b/test/test-suite/images/big-height.webp new file mode 100644 index 0000000000000000000000000000000000000000..752a1696414138d543a50e8451775dc1f00b6c66 GIT binary patch literal 7222 zcmWIYbaT^_VPFV%bqWXzu!!JdU|?VZVjc#D6$}iHexAN;K;C~K0P%d?oPazCfT%bD zCEW1*@gn{ATzt9Unm7^w& zhSO*&7|kuCWx;5fIa(u()|{j5g3<{9 literal 0 HcmV?d00001 diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index a0cb4966..b146c9bd 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -17,8 +17,8 @@ from helpers import \ GIF_ANIM_DISPOSE_PREVIOUS_FILE, \ GIF_ANIM_DISPOSE_PREVIOUS_EXPECTED_PNG_FILE, \ temp_filename, assert_almost_equal_objects, have, skip_if_no, \ - TIF1_FILE, TIF2_FILE, TIF4_FILE, WEBP_LOOKS_LIKE_SVG_FILE - + TIF1_FILE, TIF2_FILE, TIF4_FILE, WEBP_LOOKS_LIKE_SVG_FILE, \ + WEBP_ANIMATED_FILE class TestForeign: tempdir = None @@ -694,6 +694,12 @@ class TestForeign: x = pyvips.Image.new_from_file(WEBP_LOOKS_LIKE_SVG_FILE) assert x.get("vips-loader") == "webpload" + # Animated WebP roundtrip + x = pyvips.Image.new_from_file(WEBP_ANIMATED_FILE, n=-1) + assert x.width == 13 + assert x.height == 16393 + buf = x.webpsave_buffer() + @skip_if_no("analyzeload") def test_analyzeload(self): def analyze_valid(im): From 460efa73fa00f90c09aa9c63c322f0dee1c60b10 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 18 Dec 2020 10:12:26 +0000 Subject: [PATCH 2/2] bump version for animated webp load fix --- ChangeLog | 3 +++ configure.ac | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31bc7ffd..eee28d62 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +18/12/20 started 8.10.5 +- fix potential /0 in animated webp load [lovell] + 14/12/20 started 8.10.4 - fix spng detection diff --git a/configure.ac b/configure.ac index ed4d2361..4e38020e 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # also update the version number in the m4 macros below -AC_INIT([vips], [8.10.4], [vipsip@jiscmail.ac.uk]) +AC_INIT([vips], [8.10.5], [vipsip@jiscmail.ac.uk]) # required for gobject-introspection AC_PREREQ(2.62) @@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4]) # user-visible library versioning m4_define([vips_major_version], [8]) m4_define([vips_minor_version], [10]) -m4_define([vips_micro_version], [4]) +m4_define([vips_micro_version], [5]) m4_define([vips_version], [vips_major_version.vips_minor_version.vips_micro_version]) @@ -38,7 +38,7 @@ VIPS_VERSION_STRING=$VIPS_VERSION-`date -u -r $srcdir/ChangeLog` # binary interface changes not backwards compatible?: reset age to 0 LIBRARY_CURRENT=54 -LIBRARY_REVISION=5 +LIBRARY_REVISION=6 LIBRARY_AGE=12 # patched into include/vips/version.h