diff options
author | erouault <erouault> | 2017-02-18 18:46:00 +0000 |
---|---|---|
committer | erouault <erouault> | 2017-02-18 18:46:00 +0000 |
commit | fc6714e0c6bb22bbbd517a930106000572833e45 (patch) | |
tree | 913f2bddec6bbd1d187c8ed0279838bda2837dac | |
parent | afeef7b1c24bd558f77522fb02add430ee96d91e (diff) | |
download | libtiff-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-- | ChangeLog | 7 | ||||
-rw-r--r-- | libtiff/tif_lzw.c | 21 |
2 files changed, 27 insertions, 1 deletions
@@ -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 */ |