From 130ef8d6574bc2ee44156851828a41bc04060243 Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Wed, 5 Jul 2023 12:29:13 +0200
Subject: [PATCH] WebP decoder: fix error when reading a 3-band blob in a RGBA
image
Fixes regression of 350ff161c8a61b6483a1e4689e09cd47dd0dd5f9 (master only)
---
libtiff/tif_webp.c | 8 +++++++-
test/CMakeLists.txt | 3 +++
test/Makefile.am | 1 +
.../webp_lossless_rgba_alpha_fully_opaque.tif | Bin 0 -> 738 bytes
4 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 test/images/webp_lossless_rgba_alpha_fully_opaque.tif
diff --git a/libtiff/tif_webp.c b/libtiff/tif_webp.c
index c34b0b14..5ed4194d 100644
--- a/libtiff/tif_webp.c
+++ b/libtiff/tif_webp.c
@@ -192,7 +192,13 @@ static int TWebPDecode(TIFF *tif, uint8_t *op, tmsize_t occ, uint16_t s)
}
const int webp_bands = config.input.has_alpha ? 4 : 3;
- if (webp_bands != sp->nSamples)
+ if (webp_bands != sp->nSamples &&
+ /* We accept the situation where the WebP blob has only 3 bands,
+ * whereas the raster is 4 bands. This can happen when the alpha
+ * channel is fully opaque, and WebP decoding works fine in that
+ * situation.
+ */
+ !(webp_bands == 3 && sp->nSamples == 4))
{
TIFFErrorExtR(tif, module,
"WebP blob band count is %d. Expected %d", webp_bands,
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 098007c6..73cff5af 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -395,6 +395,9 @@ if(tiff-tools)
add_convert_test(tiffcp noner1 "-c none -r 1" "images/lzw-single-strip.tiff" FALSE)
add_convert_test(tiffcp float64_lzw_2_le "-c lzw:2" "images/test_float64_predictor2_le_lzw.tif" FALSE)
add_convert_test(tiffcp float64_lzw_2_be "-c lzw:2" "images/test_float64_predictor2_be_lzw.tif" FALSE)
+ if(WEBP_SUPPORT)
+ add_convert_test(tiffcp webp_lossless_rgba_alpha_fully_opaque "-c none" "images/webp_lossless_rgba_alpha_fully_opaque.tif" FALSE)
+ endif()
# tiffdump
add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff")
diff --git a/test/Makefile.am b/test/Makefile.am
index 0a7f9ad5..2e6140fe 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -222,6 +222,7 @@ IMAGES_EXTRA_DIST = \
images/test_ifd_loop_to_first.tif \
images/test_two_ifds.tif \
images/test_ifd_loop_subifd.tif \
+ images/webp_lossless_rgba_alpha_fully_opaque.tif \
$(PNMIMAGES) \
$(TIFFIMAGES)
diff --git a/test/images/webp_lossless_rgba_alpha_fully_opaque.tif b/test/images/webp_lossless_rgba_alpha_fully_opaque.tif
new file mode 100644
index 0000000000000000000000000000000000000000..bd22574dbe8e8c510b405623b1da8cb18891c548
GIT binary patch
literal 738
zcmebD)MDUZU|<krU|?isU<9&6fS3`9%>-n#0L5+rF*8&=@Gt`d8<foi6c=P<0qbP|
zazvrxAU$GGHponIsG3JWwhUApWM2@HIl(|SNFPWIUo#H_Gmwq}Dr#!sVPFHYOMvY4
z?aT}cK=u+Kdt*BjgA9=U1jue!!o*MnWWNGp5a579Mxe_;(8k@x(Z@HnBrzqiB+-sb
zLBYneBsEtdFEKaOR>|4lHz3G0IM~zQFFwdM%rz+3)5+7vGbB<;AtgUIF*DCr$<x=-
z-8DWqBq-E5Bs9oX$<D_=IM@fM$3`DykR6weKB^56XE69VKo~F@DvX12cqZitk~%Zb
z2TX(5AlEZ6urq*y2J9Co&BU^?T@)nGv9X<vL6m_F7?F$&eaZ|xAUZsQ1x#xy`#HK8
znJefkgogMkRORQTDi|92)qn+S7=k?A+(0oK?&=f}7GU9X7Rc5YKET4z%F{SW=jN^Z
z(N5V32?;L_9yxO9*r9{n{_o4=>dXZ%{x9L=N#Myl$5#G1?M@eyRbs|5;Vcgs{oDna
zuhtkh9(I_NcR#84SLyq_ZE7;6AKuO{PZv1bpt1dC-nQU&i&b_-&Rz>#13hgP2WH7E
zzw)%+b+6a+Yq@u?T~_N~pWFRxT~zqLU4Cmm&Seenx{#v1%Xr@LkBikZ&9(2@Zk-#b
z(r$D1`rOLHi)|*g@;o=*uJKo}l<$4dyY=_)SM1vJp0D)o`R8vepC4xX-_OGU0GmRv
A!vFvP
literal 0
HcmV?d00001