libtiff: Add test for Fax3 decoding issues (refs #513)

From 9477634d2aba898f2b390d4e8c28f6aa556f8aee Mon Sep 17 00:00:00 2001
From: Even Rouault <[EMAIL REDACTED]>
Date: Sat, 21 Jan 2023 16:54:59 +0100
Subject: [PATCH] Add test for Fax3 decoding issues (refs #513)

---
 test/CMakeLists.txt               |   3 ++-
 test/Makefile.am                  |   2 +-
 test/images/testfax3_bug_513.tiff | Bin 0 -> 198 bytes
 test/refs/o-testfax3_bug_513.tiff | Bin 0 -> 154 bytes
 test/testfax3_bug_513.sh          |  24 ++++++++++++++++++++++++
 5 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 test/images/testfax3_bug_513.tiff
 create mode 100644 test/refs/o-testfax3_bug_513.tiff
 create mode 100755 test/testfax3_bug_513.sh

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 1c24b660..b00c1f68 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -47,7 +47,8 @@ set(TIFFIMAGES
     images/quad-lzw-compat.tiff
     images/lzw-single-strip.tiff
     images/testfax4.tiff
-    images/testfax3_bug_513.tiff)
+    images/testfax3_bug_513.tiff
+)
 # TIFF images using old-jpeg.  Unused unless JPEG support is enabled.
 set(TIFFIMAGES_OJPEG)
 
diff --git a/test/Makefile.am b/test/Makefile.am
index b53b27fa..b0fe276a 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -170,7 +170,7 @@ REFFILES = \
 	refs/o-tiff2ps-PS2.ps \
 	refs/o-tiff2ps-PS3.ps \
 	refs/o-testfax4.tiff \
-	refs/o-testfax3_bug_513.sh.tiff \
+	refs/o-testfax3_bug_513.tiff \
 	refs/o-deflate-last-strip-extra-data.tiff
 
 # This list should contain all of the TIFF files in the 'images'
diff --git a/test/images/testfax3_bug_513.tiff b/test/images/testfax3_bug_513.tiff
new file mode 100644
index 0000000000000000000000000000000000000000..41544849bc750acdd966109aeb7f2bafacd54431
GIT binary patch
literal 198
zcmebD)M7AT00Q9<D_OpF=Y<zul)xATjOZdIRy+(0jLZy-Kn)5&%m`&O0ohDYHb{;c
w%4P<#*`RD7lR=P?1+13?$QD9UFN(w#gR((pibK_F0NFA~YE+=&Kw&Td0MFPGm;e9(

literal 0
HcmV?d00001

diff --git a/test/refs/o-testfax3_bug_513.tiff b/test/refs/o-testfax3_bug_513.tiff
new file mode 100644
index 0000000000000000000000000000000000000000..cf3b8687941c65d7153e5e73d968bd2d2c525a60
GIT binary patch
literal 154
zcmebD)M5}|U|?7U1ff8{&A`CO%)kf~Q2=5_D4Pk$W`eRoa?D6<HYgh?%pl0f0@lj`
ZWD6mw5k+E)LD?WP#gWv@AgKYF1pxYD1=9ck

literal 0
HcmV?d00001

diff --git a/test/testfax3_bug_513.sh b/test/testfax3_bug_513.sh
new file mode 100755
index 00000000..751db960
--- /dev/null
+++ b/test/testfax3_bug_513.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+#
+# check decoding of a CCITT Group 3 encoded TIFF
+# hitting https://gitlab.com/libtiff/libtiff/-/issues/513
+. ${srcdir:-.}/common.sh
+infile="${IMAGES}/testfax3_bug_513.tiff"
+outfile="o-testfax3_bug_513.tiff"
+rm -f $outfile
+echo "$MEMCHECK ${TIFFCP} -c none $infile $outfile"
+eval "$MEMCHECK ${TIFFCP} -c none $infile $outfile"
+status=$?
+if [ $status != 0 ] ; then
+  echo "Returned failed status $status!"
+  echo "Output (if any) is in \"${outfile}\"."
+  exit $status
+fi
+echo "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+eval "$MEMCHECK ${TIFFCMP} $outfile ${REFS}/$outfile"
+status=$?
+if [ $status != 0 ] ; then
+  echo "Returned failed status $status!"
+  echo "\"${outfile}\" differs from reference file."
+  exit $status
+fi