diff --git a/libtiff/tif_config.h.in b/libtiff/tif_config.h.in index ed1e80fc..a799435b 100644 --- a/libtiff/tif_config.h.in +++ b/libtiff/tif_config.h.in @@ -71,6 +71,9 @@ /* Define to 1 if you have the `lfind' function. */ #undef HAVE_LFIND +/* Define to 1 if you have the header file. */ +#undef HAVE_MEMORY_H + /* Define to 1 if you have the `mmap' function. */ #undef HAVE_MMAP diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index 94d85e38..ac685dd7 100644 --- a/libtiff/tif_lzw.c +++ b/libtiff/tif_lzw.c @@ -133,6 +133,7 @@ typedef struct { long dec_restart; /* restart count */ #ifdef LZW_CHECKEOS uint64 dec_bitsleft; /* available bits in raw data */ + tmsize_t old_tif_rawcc; /* value of tif_rawcc at the end of the previous TIFLZWDecode() call */ #endif decodeFunc dec_decode; /* regular or backwards compatible */ code_t* dec_codep; /* current recognized code */ @@ -318,6 +319,7 @@ LZWPreDecode(TIFF* tif, uint16 s) sp->dec_nbitsmask = MAXCODE(BITS_MIN); #ifdef LZW_CHECKEOS sp->dec_bitsleft = 0; + sp->old_tif_rawcc = 0; #endif sp->dec_free_entp = sp->dec_codetab + CODE_FIRST; /* @@ -425,7 +427,7 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) bp = (unsigned char *)tif->tif_rawcp; #ifdef LZW_CHECKEOS - sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3); + sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3); #endif nbits = sp->lzw_nbits; nextdata = sp->lzw_nextdata; @@ -553,6 +555,9 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp ); tif->tif_rawcp = (uint8*) bp; +#ifdef LZW_CHECKEOS + sp->old_tif_rawcc = tif->tif_rawcc; +#endif sp->lzw_nbits = (unsigned short) nbits; sp->lzw_nextdata = nextdata; sp->lzw_nextbits = nextbits; @@ -656,7 +661,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) bp = (unsigned char *)tif->tif_rawcp; #ifdef LZW_CHECKEOS - sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3); + sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3); #endif nbits = sp->lzw_nbits; nextdata = sp->lzw_nextdata; @@ -774,6 +779,9 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp ); tif->tif_rawcp = (uint8*) bp; +#ifdef LZW_CHECKEOS + sp->old_tif_rawcc = tif->tif_rawcc; +#endif sp->lzw_nbits = (unsigned short)nbits; sp->lzw_nextdata = nextdata; sp->lzw_nextbits = nextbits; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 912be19c..266e3fcf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,6 +44,7 @@ set(TESTSCRIPTS tiffcp-logluv.sh tiffcp-thumbnail.sh tiffcp-lzw-compat.sh + tiffcp-lzw-scanline-decode.sh tiffdump.sh tiffinfo.sh tiffcp-split.sh @@ -120,7 +121,8 @@ set(TIFFIMAGES images/rgb-3c-16b.tiff images/rgb-3c-8b.tiff images/quad-tile.jpg.tiff - images/quad-lzw-compat.tiff) + images/quad-lzw-compat.tiff + images/lzw-single-strip.tiff) set(BMPIMAGES images/palette-1c-8b.bmp @@ -335,6 +337,7 @@ add_convert_test(tiffcp g32d "-c g3:2d" "images/miniswhite-1c-1b.ti add_convert_test(tiffcp g32dfill "-c g3:2d:fill" "images/miniswhite-1c-1b.tiff" FALSE) add_convert_test(tiffcp g4 "-c g4" "images/miniswhite-1c-1b.tiff" FALSE) add_convert_test(tiffcp none "-c none" "images/quad-lzw-compat.tiff" FALSE) +add_convert_test(tiffcp noner1 "-c none -r 1" "images/lzw-single-strip.tiff" FALSE) add_convert_test_multi(tiffcp tiffcp "" logluv "-c none" "-c sgilog" "" "images/logluv-3c-16b.tiff" FALSE) add_convert_test_multi(tiffcp thumbnail "" thumbnail "g3:1d" "" "" diff --git a/test/Makefile.am b/test/Makefile.am index 2052487c..52a3fa4b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -79,6 +79,7 @@ TESTSCRIPTS = \ tiffcp-logluv.sh \ tiffcp-thumbnail.sh \ tiffcp-lzw-compat.sh \ + tiffcp-lzw-scanline-decode.sh \ tiffdump.sh \ tiffinfo.sh \ tiffcp-split.sh \ @@ -158,7 +159,8 @@ TIFFIMAGES = \ images/rgb-3c-16b.tiff \ images/rgb-3c-8b.tiff \ images/quad-tile.jpg.tiff \ - images/quad-lzw-compat.tiff + images/quad-lzw-compat.tiff \ + images/lzw-single-strip.tiff PNMIMAGES = \ images/minisblack-1c-8b.pgm \ diff --git a/test/common.sh b/test/common.sh index 6b1380dd..42c38737 100644 --- a/test/common.sh +++ b/test/common.sh @@ -41,6 +41,7 @@ IMG_RGB_3C_16B=${IMAGES}/rgb-3c-16b.tiff IMG_RGB_3C_8B=${IMAGES}/rgb-3c-8b.tiff IMG_MINISBLACK_2C_8B_ALPHA=${IMAGES}/minisblack-2c-8b-alpha.tiff IMG_QUAD_LZW_COMPAT=${IMAGES}/quad-lzw-compat.tiff +IMG_LZW_SINGLE_STROP=${IMAGES}/lzw-single-strip.tiff IMG_MINISWHITE_1C_1B_PBM=${IMAGES}/miniswhite-1c-1b.pbm IMG_MINISBLACK_1C_8B_PGM=${IMAGES}/minisblack-1c-8b.pgm diff --git a/test/images/lzw-single-strip.tiff b/test/images/lzw-single-strip.tiff new file mode 100644 index 00000000..0ac27c6d Binary files /dev/null and b/test/images/lzw-single-strip.tiff differ diff --git a/test/tiffcp-lzw-scanline-decode.sh b/test/tiffcp-lzw-scanline-decode.sh new file mode 100755 index 00000000..11654d19 --- /dev/null +++ b/test/tiffcp-lzw-scanline-decode.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# +# Basic sanity check for tiffcp with LZW decompression +# +. ${srcdir:-.}/common.sh +f_test_convert "${TIFFCP} -c none -r 1" "${IMG_LZW_SINGLE_STROP}" "o-tiffcp-lzw-scanline-decode.tiff" \ No newline at end of file