···780780 */
781781 static const char module[] = "JPEGFixupTagsSubsampling";
782782 struct JPEGFixupTagsSubsamplingData m;
783783+ uint64 fileoffset = TIFFGetStrileOffset(tif, 0);
783784784784- _TIFFFillStriles( tif );
785785-786786- if( tif->tif_dir.td_stripbytecount == NULL
787787- || tif->tif_dir.td_stripoffset == NULL
788788- || tif->tif_dir.td_stripbytecount[0] == 0 )
785785+ if( fileoffset == 0 )
789786 {
790787 /* Do not even try to check if the first strip/tile does not
791788 yet exist, as occurs when GDAL has created a new NULL file
···804801 }
805802 m.buffercurrentbyte=NULL;
806803 m.bufferbytesleft=0;
807807- m.fileoffset=tif->tif_dir.td_stripoffset[0];
804804+ m.fileoffset=fileoffset;
808805 m.filepositioned=0;
809809- m.filebytesleft=tif->tif_dir.td_stripbytecount[0];
806806+ m.filebytesleft=TIFFGetStrileByteCount(tif, 0);
810807 if (!JPEGFixupTagsSubsamplingSec(&m))
811808 TIFFWarningExt(tif->tif_clientdata,module,
812809 "Unable to auto-correct subsampling values, likely corrupt JPEG compressed data in first strip/tile; auto-correcting skipped");
···15661563 JSAMPLE *outptr = (JSAMPLE*)tmpbuf + clumpoffset;
15671564#else
15681565 JSAMPLE *outptr = (JSAMPLE*)buf + clumpoffset;
15691569- if (cc < (tmsize_t) (clumpoffset + samples_per_clump*(clumps_per_line-1) + hsamp)) {
15661566+ if (cc < (tmsize_t)(clumpoffset + (tmsize_t)samples_per_clump*(clumps_per_line-1) + hsamp)) {
15701567 TIFFErrorExt(tif->tif_clientdata, "JPEGDecodeRaw",
15711568 "application buffer not large enough for all data, possible subsampling issue");
15721569 return 0;
···21262123 /* data is expected to be supplied in multiples of a clumpline */
21272124 /* a clumpline is equivalent to v_sampling desubsampled scanlines */
21282125 /* TODO: the following calculation of bytesperclumpline, should substitute calculation of sp->bytesperline, except that it is per v_sampling lines */
21292129- bytesperclumpline = (((sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
21302130- *(sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
21262126+ bytesperclumpline = ((((tmsize_t)sp->cinfo.c.image_width+sp->h_sampling-1)/sp->h_sampling)
21272127+ *((tmsize_t)sp->h_sampling*sp->v_sampling+2)*sp->cinfo.c.data_precision+7)
21312128 /8;
2132212921332130 nrows = ( cc / bytesperclumpline ) * sp->v_sampling;
···243243typedef struct {
244244 TIFF* tif;
245245 int decoder_ok;
246246+ int error_in_raw_data_decoding;
246247 #ifndef LIBJPEG_ENCAP_EXTERNAL
247248 JMP_BUF exit_jmpbuf;
248249 #endif
···678679 if (OJPEGReadSecondarySos(tif,s)==0)
679680 return(0);
680681 }
681681- if isTiled(tif)
682682+ if (isTiled(tif))
682683 m=tif->tif_curtile;
683684 else
684685 m=tif->tif_curstrip;
···742743 }
743744 m-=sp->subsampling_convert_clines-sp->subsampling_convert_state;
744745 sp->subsampling_convert_state=0;
746746+ sp->error_in_raw_data_decoding=0;
745747 }
746748 while (m>=sp->subsampling_convert_clines)
747749 {
···792794 TIFFErrorExt(tif->tif_clientdata,module,"Cannot decode: decoder not correctly initialized");
793795 return 0;
794796 }
797797+ if( sp->error_in_raw_data_decoding )
798798+ {
799799+ return 0;
800800+ }
795801 if (sp->libjpeg_jpeg_query_style==0)
796802 {
797803 if (OJPEGDecodeRaw(tif,buf,cc)==0)
···831837 {
832838 if (sp->subsampling_convert_state==0)
833839 {
840840+ const jpeg_decompress_struct* cinfo = &sp->libjpeg_jpeg_decompress_struct;
841841+ int width = 0;
842842+ int last_col_width = 0;
843843+ int jpeg_bytes;
844844+ int expected_bytes;
845845+ int i;
846846+ if (cinfo->MCUs_per_row == 0)
847847+ {
848848+ sp->error_in_raw_data_decoding = 1;
849849+ return 0;
850850+ }
851851+ for (i = 0; i < cinfo->comps_in_scan; ++i)
852852+ {
853853+ const jpeg_component_info* info = cinfo->cur_comp_info[i];
854854+#if JPEG_LIB_VERSION >= 70
855855+ width += info->MCU_width * info->DCT_h_scaled_size;
856856+ last_col_width += info->last_col_width * info->DCT_h_scaled_size;
857857+#else
858858+ width += info->MCU_width * info->DCT_scaled_size;
859859+ last_col_width += info->last_col_width * info->DCT_scaled_size;
860860+#endif
861861+ }
862862+ jpeg_bytes = (cinfo->MCUs_per_row - 1) * width + last_col_width;
863863+ expected_bytes = sp->subsampling_convert_clinelenout * sp->subsampling_ver * sp->subsampling_hor;
864864+ if (jpeg_bytes != expected_bytes)
865865+ {
866866+ TIFFErrorExt(tif->tif_clientdata,module,"Inconsistent number of MCU in codestream");
867867+ sp->error_in_raw_data_decoding = 1;
868868+ return(0);
869869+ }
834870 if (jpeg_read_raw_data_encap(sp,&(sp->libjpeg_jpeg_decompress_struct),sp->subsampling_convert_ycbcrimage,sp->subsampling_ver*8)==0)
871871+ {
872872+ sp->error_in_raw_data_decoding = 1;
835873 return(0);
874874+ }
836875 }
837876 oy=sp->subsampling_convert_ybuf+sp->subsampling_convert_state*sp->subsampling_ver*sp->subsampling_convert_ylinelen;
838877 ocb=sp->subsampling_convert_cbbuf+sp->subsampling_convert_state*sp->subsampling_convert_clinelen;
···9901029 OJPEGState* sp=(OJPEGState*)tif->tif_data;
9911030 uint8 mh;
9921031 uint8 mv;
993993- _TIFFFillStriles( tif );
99410329951033 assert(sp->subsamplingcorrect_done==0);
9961034 if ((tif->tif_dir.td_samplesperpixel!=3) || ((tif->tif_dir.td_photometric!=PHOTOMETRIC_YCBCR) &&
···10461084 assert(sp->readheader_done==0);
10471085 sp->image_width=tif->tif_dir.td_imagewidth;
10481086 sp->image_length=tif->tif_dir.td_imagelength;
10491049- if isTiled(tif)
10871087+ if (isTiled(tif))
10501088 {
10511089 sp->strile_width=tif->tif_dir.td_tilewidth;
10521090 sp->strile_length=tif->tif_dir.td_tilelength;
···10821120 }
10831121 if (sp->strile_length<sp->image_length)
10841122 {
11231123+ if (((sp->subsampling_hor!=1) && (sp->subsampling_hor!=2) && (sp->subsampling_hor!=4)) ||
11241124+ ((sp->subsampling_ver!=1) && (sp->subsampling_ver!=2) && (sp->subsampling_ver!=4)))
11251125+ {
11261126+ TIFFErrorExt(tif->tif_clientdata,module,"Invalid subsampling values");
11271127+ return(0);
11281128+ }
10851129 if (sp->strile_length%(sp->subsampling_ver*8)!=0)
10861130 {
10871131 TIFFErrorExt(tif->tif_clientdata,module,"Incompatible vertical subsampling and image strip/tile length");
···11971241 sp->subsampling_convert_ybuflen=sp->subsampling_convert_ylinelen*sp->subsampling_convert_ylines;
11981242 sp->subsampling_convert_cbuflen=sp->subsampling_convert_clinelen*sp->subsampling_convert_clines;
11991243 sp->subsampling_convert_ycbcrbuflen=sp->subsampling_convert_ybuflen+2*sp->subsampling_convert_cbuflen;
12001200- sp->subsampling_convert_ycbcrbuf=_TIFFmalloc(sp->subsampling_convert_ycbcrbuflen);
12441244+ /* The calloc is not normally necessary, except in some edge/broken cases */
12451245+ /* for example for a tiled image of height 1 with a tile height of 1 and subsampling_hor=subsampling_ver=2 */
12461246+ /* In that case, libjpeg will only fill the 8 first lines of the 16 lines */
12471247+ /* See https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=16844 */
12481248+ /* Even if this case is allowed (?), its handling is broken because OJPEGPreDecode() should also likely */
12491249+ /* reset subsampling_convert_state to 0 when changing tile. */
12501250+ sp->subsampling_convert_ycbcrbuf=_TIFFcalloc(1, sp->subsampling_convert_ycbcrbuflen);
12011251 if (sp->subsampling_convert_ycbcrbuf==0)
12021252 {
12031253 TIFFErrorExt(tif->tif_clientdata,module,"Out of memory");
···12231273 *m++=sp->subsampling_convert_cbbuf+n*sp->subsampling_convert_clinelen;
12241274 for (n=0; n<sp->subsampling_convert_clines; n++)
12251275 *m++=sp->subsampling_convert_crbuf+n*sp->subsampling_convert_clinelen;
12261226- sp->subsampling_convert_clinelenout=((sp->strile_width+sp->subsampling_hor-1)/sp->subsampling_hor);
12761276+ sp->subsampling_convert_clinelenout=sp->strile_width/sp->subsampling_hor + ((sp->strile_width % sp->subsampling_hor) != 0 ? 1 : 0);
12271277 sp->subsampling_convert_state=0;
12781278+ sp->error_in_raw_data_decoding=0;
12281279 sp->bytes_per_line=sp->subsampling_convert_clinelenout*(sp->subsampling_ver*sp->subsampling_hor+2);
12291229- sp->lines_per_strile=((sp->strile_length+sp->subsampling_ver-1)/sp->subsampling_ver);
12801280+ sp->lines_per_strile=sp->strile_length/sp->subsampling_ver + ((sp->strile_length % sp->subsampling_ver) != 0 ? 1 : 0);
12301281 sp->subsampling_convert_log=1;
12311282 }
12321283 }
···12721323 }
12731324 else
12741325 {
12751275- if ((sp->jpeg_interchange_format_length==0) || (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size))
13261326+ if ((sp->jpeg_interchange_format_length==0) ||
13271327+ (sp->jpeg_interchange_format > TIFF_UINT64_MAX - sp->jpeg_interchange_format_length) ||
13281328+ (sp->jpeg_interchange_format+sp->jpeg_interchange_format_length>sp->file_size))
12761329 sp->jpeg_interchange_format_length=sp->file_size-sp->jpeg_interchange_format;
12771330 }
12781331 }
···19892042 sp->in_buffer_source=osibsStrile;
19902043 break;
19912044 case osibsStrile:
19921992- if (!_TIFFFillStriles( sp->tif )
19931993- || sp->tif->tif_dir.td_stripoffset == NULL
19941994- || sp->tif->tif_dir.td_stripbytecount == NULL)
19951995- return 0;
19961996-19972045 if (sp->in_buffer_next_strile==sp->in_buffer_strile_count)
19982046 sp->in_buffer_source=osibsEof;
19992047 else
20002048 {
20012001- sp->in_buffer_file_pos=sp->tif->tif_dir.td_stripoffset[sp->in_buffer_next_strile];
20492049+ int err = 0;
20502050+ sp->in_buffer_file_pos=TIFFGetStrileOffsetWithErr(sp->tif, sp->in_buffer_next_strile, &err);
20512051+ if( err )
20522052+ return 0;
20022053 if (sp->in_buffer_file_pos!=0)
20032054 {
20552055+ uint64 bytecount = TIFFGetStrileByteCountWithErr(sp->tif, sp->in_buffer_next_strile, &err);
20562056+ if( err )
20572057+ return 0;
20042058 if (sp->in_buffer_file_pos>=sp->file_size)
20052059 sp->in_buffer_file_pos=0;
20062006- else if (sp->tif->tif_dir.td_stripbytecount==NULL)
20602060+ else if (bytecount==0)
20072061 sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos;
20082062 else
20092063 {
20102010- if (sp->tif->tif_dir.td_stripbytecount == 0) {
20112011- TIFFErrorExt(sp->tif->tif_clientdata,sp->tif->tif_name,"Strip byte counts are missing");
20122012- return(0);
20132013- }
20142014- sp->in_buffer_file_togo=sp->tif->tif_dir.td_stripbytecount[sp->in_buffer_next_strile];
20642064+ sp->in_buffer_file_togo=bytecount;
20152065 if (sp->in_buffer_file_togo==0)
20162066 sp->in_buffer_file_pos=0;
20172017- else if (sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size)
20672067+ else if (sp->in_buffer_file_pos > TIFF_UINT64_MAX - sp->in_buffer_file_togo ||
20682068+ sp->in_buffer_file_pos+sp->in_buffer_file_togo>sp->file_size)
20182069 sp->in_buffer_file_togo=sp->file_size-sp->in_buffer_file_pos;
20192070 }
20202071 }
+18-1
dll/3rdparty/libtiff/tif_open.c
···2525/*
2626 * TIFF Library.
2727 */
2828-2928#include <precomp.h>
30293130/*
···132131 if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) {
133132 TIFFErrorExt(clientdata, module,
134133 "One of the client procedures is NULL pointer.");
134134+ _TIFFfree(tif);
135135 goto bad2;
136136 }
137137 tif->tif_readproc = readproc;
···182182 * 'h' read TIFF header only, do not load the first IFD
183183 * '4' ClassicTIFF for creating a file (default)
184184 * '8' BigTIFF for creating a file
185185+ * 'D' enable use of deferred strip/tile offset/bytecount array loading.
186186+ * 'O' on-demand loading of values instead of whole array loading (implies D)
185187 *
186188 * The use of the 'l' and 'b' flags is strongly discouraged.
187189 * These flags are provided solely because numerous vendors,
···263265 if (m&O_CREAT)
264266 tif->tif_flags |= TIFF_BIGTIFF;
265267 break;
268268+ case 'D':
269269+ tif->tif_flags |= TIFF_DEFERSTRILELOAD;
270270+ break;
271271+ case 'O':
272272+ if( m == O_RDONLY )
273273+ tif->tif_flags |= (TIFF_LAZYSTRILELOAD | TIFF_DEFERSTRILELOAD);
274274+ break;
266275 }
276276+277277+#ifdef DEFER_STRILE_LOAD
278278+ /* Compatibility with old DEFER_STRILE_LOAD compilation flag */
279279+ /* Probably unneeded, since to the best of my knowledge (E. Rouault) */
280280+ /* GDAL was the only user of this, and will now use the new 'D' flag */
281281+ tif->tif_flags |= TIFF_DEFERSTRILELOAD;
282282+#endif
283283+267284 /*
268285 * Read in TIFF header.
269286 */
···2121 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2222 * OF THIS SOFTWARE.
2323 */
2424-2524#include <precomp.h>
26252726static const char TIFFVersion[] = TIFFLIB_VERSION_STR;
···5858 uint32 toff_long;
5959 uint64 toff_long8;
6060 } tdir_offset; /* either offset or the data itself if fits */
6161+ uint8 tdir_ignore; /* flag status to ignore tag when parsing tags in tif_dirread.c */
6162} TIFFDirEntry;
62636364/*
···9798 * number of striles */
9899 uint32 td_stripsperimage;
99100 uint32 td_nstrips; /* size of offset & bytecount arrays */
100100- uint64* td_stripoffset;
101101- uint64* td_stripbytecount;
101101+ uint64* td_stripoffset_p; /* should be accessed with TIFFGetStrileOffset */
102102+ uint64* td_stripbytecount_p; /* should be accessed with TIFFGetStrileByteCount */
103103+ uint32 td_stripoffsetbyteallocsize; /* number of elements currently allocated for td_stripoffset/td_stripbytecount. Only used if TIFF_LAZYSTRILELOAD is set */
104104+#ifdef STRIPBYTECOUNTSORTED_UNUSED
102105 int td_stripbytecountsorted; /* is the bytecount array sorted ascending? */
103103-#if defined(DEFER_STRILE_LOAD)
106106+#endif
104107 TIFFDirEntry td_stripoffset_entry; /* for deferred loading */
105108 TIFFDirEntry td_stripbytecount_entry; /* for deferred loading */
106106-#endif
107109 uint16 td_nsubifd;
108110 uint64* td_subifd;
109111 /* YCbCr parameters */
···118120119121 int td_customValueCount;
120122 TIFFTagValue *td_customValues;
123123+124124+ unsigned char td_deferstrilearraywriting; /* see TIFFDeferStrileArrayWriting() */
121125} TIFFDirectory;
122126123127/*
···7777#define FALSE 0
7878#endif
79798080+#define TIFF_SIZE_T_MAX ((size_t) ~ ((size_t)0))
8181+#define TIFF_TMSIZE_T_MAX (tmsize_t)(TIFF_SIZE_T_MAX >> 1)
8282+8383+/*
8484+ * Largest 32-bit unsigned integer value.
8585+ */
8686+#define TIFF_UINT32_MAX 0xFFFFFFFFU
8787+8888+/*
8989+ * Largest 64-bit unsigned integer value.
9090+ */
9191+#define TIFF_UINT64_MAX (((uint64)(TIFF_UINT32_MAX)) << 32 | TIFF_UINT32_MAX)
9292+8093typedef struct client_info {
8194 struct client_info *next;
8295 void *data;
···127140 #define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
128141 #define TIFF_PERSAMPLE 0x400000U /* get/set per sample tags as arrays */
129142 #define TIFF_BUFFERMMAP 0x800000U /* read buffer (tif_rawdata) points into mmap() memory */
143143+ #define TIFF_DEFERSTRILELOAD 0x1000000U /* defer strip/tile offset/bytecount array loading. */
144144+ #define TIFF_LAZYSTRILELOAD 0x2000000U /* lazy/ondemand loading of strip/tile offset/bytecount values. Only used if TIFF_DEFERSTRILELOAD is set and in read-only mode */
145145+ #define TIFF_CHOPPEDUPARRAYS 0x4000000U /* set when allocChoppedUpStripArrays() has modified strip array */
130146 uint64 tif_diroff; /* file offset of current directory */
131147 uint64 tif_nextdiroff; /* file offset of following directory */
132148 uint64* tif_dirlist; /* list of offsets to already seen directories to prevent IFD looping */
···258274#define TIFFhowmany8_64(x) (((x)&0x07)?((uint64)(x)>>3)+1:(uint64)(x)>>3)
259275#define TIFFroundup_64(x, y) (TIFFhowmany_64(x,y)*(y))
260276261261-/* Safe multiply which returns zero if there is an integer overflow */
277277+/* Safe multiply which returns zero if there is an *unsigned* integer overflow. This macro is not safe for *signed* integer types */
262278#define TIFFSafeMultiply(t,v,m) ((((t)(m) != (t)0) && (((t)(((v)*(m))/(m))) == (t)(v))) ? (t)((v)*(m)) : (t)0)
263279264280#define TIFFmax(A,B) ((A)>(B)?(A):(B))
···368384369385extern uint32 _TIFFMultiply32(TIFF*, uint32, uint32, const char*);
370386extern uint64 _TIFFMultiply64(TIFF*, uint64, uint64, const char*);
387387+extern tmsize_t _TIFFMultiplySSize(TIFF*, tmsize_t, tmsize_t, const char*);
388388+extern tmsize_t _TIFFCastUInt64ToSSize(TIFF*, uint64, const char*);
371389extern void* _TIFFCheckMalloc(TIFF*, tmsize_t, tmsize_t, const char*);
372390extern void* _TIFFCheckRealloc(TIFF*, void*, tmsize_t, tmsize_t, const char*);
373391374392extern double _TIFFUInt64ToDouble(uint64);
375393extern float _TIFFUInt64ToFloat(uint64);
394394+395395+extern float _TIFFClampDoubleToFloat(double);
376396377397extern tmsize_t
378398_TIFFReadEncodedStripAndAllocBuffer(TIFF* tif, uint32 strip,
+2-2
sdk/include/reactos/libs/libtiff/tiffvers.h
···11-#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.10\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
11+#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.1.0\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
22/*
33 * This define can be used in code that requires
44 * compilation-related definitions specific to a
···66 * version checking should be done based on the
77 * string returned by TIFFGetVersion.
88 */
99-#define TIFFLIB_VERSION 20181110
99+#define TIFFLIB_VERSION 20191103