From b967dd4705662208d73556b096298ad7608aee76 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 8 Dec 2021 22:58:32 +0100 Subject: LZW codec: fix support for strips/tiles > 2 GB on Windows --- libtiff/tif_lzw.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index a7f173ce..9920d7c9 100644 --- a/libtiff/tif_lzw.c +++ b/libtiff/tif_lzw.c @@ -130,7 +130,7 @@ typedef struct { /* Decoding specific data */ long dec_nbitsmask; /* lzw_nbits 1 bits, right adjusted */ - long dec_restart; /* restart count */ + tmsize_t dec_restart; /* restart count */ #ifdef LZW_CHECKEOS uint64_t dec_bitsleft; /* available bits in raw data */ tmsize_t old_tif_rawcc; /* value of tif_rawcc at the end of the previous TIFLZWDecode() call */ @@ -144,11 +144,11 @@ typedef struct { /* Encoding specific data */ int enc_oldcode; /* last code encountered */ - long enc_checkpoint; /* point at which to clear table */ + tmsize_t enc_checkpoint; /* point at which to clear table */ #define CHECK_GAP 10000 /* enc_ratio check interval */ long enc_ratio; /* current compression ratio */ - long enc_incount; /* (input) data bytes encoded */ - long enc_outcount; /* encoded (output) bytes */ + tmsize_t enc_incount; /* (input) data bytes encoded */ + tmsize_t enc_outcount; /* encoded (output) bytes */ uint8_t* enc_rawlimit; /* bound on tif_rawdata buffer */ hash_t* enc_hashtab; /* kept separate for small machines */ } LZWCodecState; @@ -362,7 +362,7 @@ LZWDecode(TIFF* tif, uint8_t* op0, tmsize_t occ0, uint16_t s) static const char module[] = "LZWDecode"; LZWCodecState *sp = DecoderState(tif); uint8_t *op = (uint8_t*) op0; - long occ = (long) occ0; + tmsize_t occ = occ0; uint8_t *tp; uint8_t *bp; hcode_t code; @@ -375,16 +375,11 @@ LZWDecode(TIFF* tif, uint8_t* op0, tmsize_t occ0, uint16_t s) assert(sp != NULL); assert(sp->dec_codetab != NULL); - /* - Fail if value does not fit in long. - */ - if ((tmsize_t) occ != occ0) - return (0); /* * Restart interrupted output operation. */ if (sp->dec_restart) { - long residue; + tmsize_t residue; codep = sp->dec_codep; residue = codep->length - sp->dec_restart; @@ -516,7 +511,7 @@ LZWDecode(TIFF* tif, uint8_t* op0, tmsize_t occ0, uint16_t s) codep = codep->next; } while (codep && codep->length > occ); if (codep) { - sp->dec_restart = (long)occ; + sp->dec_restart = occ; tp = op + occ; do { *--tp = codep->value; @@ -590,7 +585,7 @@ LZWDecodeCompat(TIFF* tif, uint8_t* op0, tmsize_t occ0, uint16_t s) static const char module[] = "LZWDecodeCompat"; LZWCodecState *sp = DecoderState(tif); uint8_t *op = (uint8_t*) op0; - long occ = (long) occ0; + tmsize_t occ = occ0; uint8_t *tp; uint8_t *bp; int code, nbits; @@ -601,12 +596,6 @@ LZWDecodeCompat(TIFF* tif, uint8_t* op0, tmsize_t occ0, uint16_t s) (void) s; assert(sp != NULL); - /* - Fail if value does not fit in long. - */ - if ((tmsize_t) occ != occ0) - return (0); - /* * Restart interrupted output operation. */ @@ -883,7 +872,7 @@ LZWEncode(TIFF* tif, uint8_t* bp, tmsize_t cc, uint16_t s) register int h, c; hcode_t ent; long disp; - long incount, outcount, checkpoint; + tmsize_t incount, outcount, checkpoint; unsigned long nextdata; long nextbits; int free_ent, maxcode, nbits; @@ -1049,7 +1038,7 @@ LZWPostEncode(TIFF* tif) uint8_t* op = tif->tif_rawcp; long nextbits = sp->lzw_nextbits; unsigned long nextdata = sp->lzw_nextdata; - long outcount = sp->enc_outcount; + tmsize_t outcount = sp->enc_outcount; int nbits = sp->lzw_nbits; if (op > sp->enc_rawlimit) { -- cgit v1.2.1