From 42bfc7006acd0ee14f595578b8d9cce420c4476f Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 30 Aug 2015 21:07:44 +0000 Subject: [PATCH] * libtiff/tif_lzw.c: make nextdata a unsigned type to avoid undefined behaviour with shifts (gcc -fsanitize=shift) --- ChangeLog | 4 ++++ libtiff/tif_lzw.c | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index aee767cb..c2a47066 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2015-08-30 Even Rouault + * libtiff/tif_lzw.c: make nextdata a unsigned type to avoid + undefined behaviour with shifts (gcc -fsanitize=shift) + +2015-08-30 Even Rouault * libtiff/tif_fax3.c, libtiff/tif_lzw.c, libtiff/tif_predict.c: add explicit masking with 0xff before casting to unsigned char (make icc -check=conversions happy) diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c index ab04bbaa..9b76dd03 100644 --- a/libtiff/tif_lzw.c +++ b/libtiff/tif_lzw.c @@ -1,4 +1,4 @@ -/* $Id: tif_lzw.c,v 1.48 2015-08-30 20:49:55 erouault Exp $ */ +/* $Id: tif_lzw.c,v 1.49 2015-08-30 21:07:44 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -94,7 +94,7 @@ typedef struct { unsigned short nbits; /* # of bits/code */ unsigned short maxcode; /* maximum code for lzw_nbits */ unsigned short free_ent; /* next free entry in hash table */ - long nextdata; /* next bits of i/o */ + unsigned long nextdata; /* next bits of i/o */ long nextbits; /* # of valid bits in lzw_nextdata */ int rw_mode; /* preserve rw_mode from init */ @@ -367,7 +367,8 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) unsigned char *bp; hcode_t code; int len; - long nbits, nextbits, nextdata, nbitsmask; + long nbits, nextbits, nbitsmask; + unsigned long nextdata; code_t *codep, *free_entp, *maxcodep, *oldcodep; (void) s; @@ -874,7 +875,8 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) hcode_t ent; long disp; long incount, outcount, checkpoint; - long nextdata, nextbits; + unsigned long nextdata; + long nextbits; int free_ent, maxcode, nbits; uint8* op; uint8* limit; @@ -1036,7 +1038,7 @@ LZWPostEncode(TIFF* tif) register LZWCodecState *sp = EncoderState(tif); uint8* op = tif->tif_rawcp; long nextbits = sp->lzw_nextbits; - long nextdata = sp->lzw_nextdata; + unsigned long nextdata = sp->lzw_nextdata; long outcount = sp->enc_outcount; int nbits = sp->lzw_nbits;