summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerouault <erouault>2017-02-18 18:46:00 +0000
committererouault <erouault>2017-02-18 18:46:00 +0000
commitfc6714e0c6bb22bbbd517a930106000572833e45 (patch)
tree913f2bddec6bbd1d187c8ed0279838bda2837dac
parentafeef7b1c24bd558f77522fb02add430ee96d91e (diff)
downloadlibtiff-fc6714e0c6bb22bbbd517a930106000572833e45.tar.gz
* libtiff/tif_lzw.c: in LZWPostEncode(), increase, if necessary, the
code bit-width after flushing the remaining code and before emitting the EOI code. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=1982
-rw-r--r--ChangeLog7
-rw-r--r--libtiff/tif_lzw.c21
2 files changed, 27 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index fbefd1b3..bbf3d5f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2017-02-18 Even Rouault <even.rouault at spatialys.com>
+
+ * libtiff/tif_lzw.c: in LZWPostEncode(), increase, if necessary, the
+ code bit-width after flushing the remaining code and before emitting
+ the EOI code.
+ Fixes http://bugzilla.maptools.org/show_bug.cgi?id=1982
+
2017-01-31 Even Rouault <even.rouault at spatialys.com>
* libtiff/tif_jpeg.c: only run JPEGFixupTagsSubsampling() if the
diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
index 5ba35ec1..7edd13c5 100644
--- a/libtiff/tif_lzw.c
+++ b/libtiff/tif_lzw.c
@@ -1,4 +1,4 @@
-/* $Id: tif_lzw.c,v 1.53 2017-01-11 20:33:35 erouault Exp $ */
+/* $Id: tif_lzw.c,v 1.54 2017-02-18 18:46:00 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
@@ -1060,8 +1060,27 @@ LZWPostEncode(TIFF* tif)
op = tif->tif_rawdata;
}
if (sp->enc_oldcode != (hcode_t) -1) {
+ int free_ent = sp->lzw_free_ent;
+
PutNextCode(op, sp->enc_oldcode);
sp->enc_oldcode = (hcode_t) -1;
+ free_ent ++;
+
+ if (free_ent == CODE_MAX-1) {
+ /* table is full, emit clear code and reset */
+ outcount = 0;
+ PutNextCode(op, CODE_CLEAR);
+ nbits = BITS_MIN;
+ } else {
+ /*
+ * If the next entry is going to be too big for
+ * the code size, then increase it, if possible.
+ */
+ if (free_ent > sp->lzw_maxcode) {
+ nbits++;
+ assert(nbits <= BITS_MAX);
+ }
+ }
}
PutNextCode(op, CODE_EOI);
/* Explicit 0xff masking to make icc -check=conversions happy */