ReactOS  0.4.15-dev-1197-g8081ba9
tif_dirread.c File Reference
#include <precomp.h>
#include <float.h>
#include <stdlib.h>
Include dependency graph for tif_dirread.c:

Go to the source code of this file.

Classes

union  _UInt64Aligned_t
 

Macros

#define FAILED_FII   ((uint32) -1)
 
#define TIFF_INT64_MAX   ((int64)(TIFF_UINT64_MAX >> 1))
 
#define INITIAL_THRESHOLD   (1024 * 1024)
 
#define THRESHOLD_MULTIPLIER   10
 
#define MAX_THRESHOLD   (THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * INITIAL_THRESHOLD)
 
#define IO_CACHE_PAGE_SIZE   4096
 
#define TIFF_MAX(a, b)   (((a)>(b)) ? (a) : (b))
 
#define TIFF_MIN(a, b)   (((a)<(b)) ? (a) : (b))
 

Typedefs

typedef union _UInt64Aligned_t UInt64Aligned_t
 

Enumerations

enum  TIFFReadDirEntryErr {
  TIFFReadDirEntryErrOk = 0, TIFFReadDirEntryErrCount = 1, TIFFReadDirEntryErrType = 2, TIFFReadDirEntryErrIo = 3,
  TIFFReadDirEntryErrRange = 4, TIFFReadDirEntryErrPsdif = 5, TIFFReadDirEntryErrSizesan = 6, TIFFReadDirEntryErrAlloc = 7
}
 

Functions

void TIFFCvtIEEEFloatToNative (TIFF *, uint32, float *)
 
void TIFFCvtIEEEDoubleToNative (TIFF *, uint32, double *)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryByte (TIFF *tif, TIFFDirEntry *direntry, uint8 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort (TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong (TIFF *tif, TIFFDirEntry *direntry, uint32 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8 (TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat (TIFF *tif, TIFFDirEntry *direntry, float *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble (TIFF *tif, TIFFDirEntry *direntry, double *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8 (TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryArray (TIFF *tif, TIFFDirEntry *direntry, uint32 *count, uint32 desttypesize, void **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray (TIFF *tif, TIFFDirEntry *direntry, uint8 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray (TIFF *tif, TIFFDirEntry *direntry, int8 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray (TIFF *tif, TIFFDirEntry *direntry, uint16 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray (TIFF *tif, TIFFDirEntry *direntry, int16 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray (TIFF *tif, TIFFDirEntry *direntry, uint32 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray (TIFF *tif, TIFFDirEntry *direntry, int32 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array (TIFF *tif, TIFFDirEntry *direntry, uint64 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array (TIFF *tif, TIFFDirEntry *direntry, int64 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray (TIFF *tif, TIFFDirEntry *direntry, float **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray (TIFF *tif, TIFFDirEntry *direntry, double **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array (TIFF *tif, TIFFDirEntry *direntry, uint64 **value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort (TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
 
static void TIFFReadDirEntryCheckedByte (TIFF *tif, TIFFDirEntry *direntry, uint8 *value)
 
static void TIFFReadDirEntryCheckedSbyte (TIFF *tif, TIFFDirEntry *direntry, int8 *value)
 
static void TIFFReadDirEntryCheckedShort (TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
 
static void TIFFReadDirEntryCheckedSshort (TIFF *tif, TIFFDirEntry *direntry, int16 *value)
 
static void TIFFReadDirEntryCheckedLong (TIFF *tif, TIFFDirEntry *direntry, uint32 *value)
 
static void TIFFReadDirEntryCheckedSlong (TIFF *tif, TIFFDirEntry *direntry, int32 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8 (TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8 (TIFF *tif, TIFFDirEntry *direntry, int64 *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational (TIFF *tif, TIFFDirEntry *direntry, double *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational (TIFF *tif, TIFFDirEntry *direntry, double *value)
 
static void TIFFReadDirEntryCheckedFloat (TIFF *tif, TIFFDirEntry *direntry, float *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble (TIFF *tif, TIFFDirEntry *direntry, double *value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte (int8 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort (uint16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort (int16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong (uint32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte (uint8 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort (uint16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort (int16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong (uint32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte (int8 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort (int16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong (uint32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort (uint16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong (uint32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte (int8 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort (int16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong (uint32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongSlong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sbyte (int8 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sshort (int16 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong (int32 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong8 (int64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlong8Long8 (uint64 value)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryData (TIFF *tif, uint64 offset, tmsize_t size, void *dest)
 
static void TIFFReadDirEntryOutputErr (TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
 
static void TIFFReadDirectoryCheckOrder (TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
 
static TIFFDirEntryTIFFReadDirectoryFindEntry (TIFF *tif, TIFFDirEntry *dir, uint16 dircount, uint16 tagid)
 
static void TIFFReadDirectoryFindFieldInfo (TIFF *tif, uint16 tagid, uint32 *fii)
 
static int EstimateStripByteCounts (TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
 
static void MissingRequired (TIFF *, const char *)
 
static int TIFFCheckDirOffset (TIFF *tif, uint64 diroff)
 
static int CheckDirCount (TIFF *, TIFFDirEntry *, uint32)
 
static uint16 TIFFFetchDirectory (TIFF *tif, uint64 diroff, TIFFDirEntry **pdir, uint64 *nextdiroff)
 
static int TIFFFetchNormalTag (TIFF *, TIFFDirEntry *, int recover)
 
static int TIFFFetchStripThing (TIFF *tif, TIFFDirEntry *dir, uint32 nstrips, uint64 **lpp)
 
static int TIFFFetchSubjectDistance (TIFF *, TIFFDirEntry *)
 
static void ChopUpSingleUncompressedStrip (TIFF *)
 
static void TryChopUpUncompressedBigTiff (TIFF *)
 
static uint64 TIFFReadUInt64 (const uint8 *value)
 
static int _TIFFGetMaxColorChannels (uint16 photometric)
 
static int _TIFFFillStrilesInternal (TIFF *tif, int loadStripByteCount)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc (TIFF *tif, uint64 offset, tmsize_t size, void **pdest)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit (TIFF *tif, TIFFDirEntry *direntry, uint32 *count, uint32 desttypesize, void **value, uint64 maxcount)
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8ArrayWithLimit (TIFF *tif, TIFFDirEntry *direntry, uint64 **value, uint64 maxcount)
 
static int ByteCountLooksBad (TIFF *tif)
 
int TIFFReadDirectory (TIFF *tif)
 
int TIFFReadCustomDirectory (TIFF *tif, toff_t diroff, const TIFFFieldArray *infoarray)
 
int TIFFReadEXIFDirectory (TIFF *tif, toff_t diroff)
 
static void allocChoppedUpStripArrays (TIFF *tif, uint32 nstrips, uint64 stripbytes, uint32 rowsperstrip)
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64 _TIFFUnsanitizedAddUInt64AndInt (uint64 a, int b)
 
static int _TIFFPartialReadStripArray (TIFF *tif, TIFFDirEntry *dirent, int strile, uint64 *panVals)
 
static int _TIFFFetchStrileValue (TIFF *tif, uint32 strile, TIFFDirEntry *dirent, uint64 **parray)
 
static uint64 _TIFFGetStrileOffsetOrByteCountValue (TIFF *tif, uint32 strile, TIFFDirEntry *dirent, uint64 **parray, int *pbErr)
 
uint64 TIFFGetStrileOffset (TIFF *tif, uint32 strile)
 
uint64 TIFFGetStrileOffsetWithErr (TIFF *tif, uint32 strile, int *pbErr)
 
uint64 TIFFGetStrileByteCount (TIFF *tif, uint32 strile)
 
uint64 TIFFGetStrileByteCountWithErr (TIFF *tif, uint32 strile, int *pbErr)
 
int _TIFFFillStriles (TIFF *tif)
 

Macro Definition Documentation

◆ FAILED_FII

#define FAILED_FII   ((uint32) -1)

Definition at line 41 of file tif_dirread.c.

◆ INITIAL_THRESHOLD

#define INITIAL_THRESHOLD   (1024 * 1024)

Definition at line 774 of file tif_dirread.c.

◆ IO_CACHE_PAGE_SIZE

#define IO_CACHE_PAGE_SIZE   4096

◆ MAX_THRESHOLD

◆ THRESHOLD_MULTIPLIER

#define THRESHOLD_MULTIPLIER   10

Definition at line 775 of file tif_dirread.c.

◆ TIFF_INT64_MAX

#define TIFF_INT64_MAX   ((int64)(TIFF_UINT64_MAX >> 1))

Definition at line 46 of file tif_dirread.c.

◆ TIFF_MAX

#define TIFF_MAX (   a,
  b 
)    (((a)>(b)) ? (a) : (b))

◆ TIFF_MIN

#define TIFF_MIN (   a,
  b 
)    (((a)<(b)) ? (a) : (b))

Typedef Documentation

◆ UInt64Aligned_t

Enumeration Type Documentation

◆ TIFFReadDirEntryErr

Enumerator
TIFFReadDirEntryErrOk 
TIFFReadDirEntryErrCount 
TIFFReadDirEntryErrType 
TIFFReadDirEntryErrIo 
TIFFReadDirEntryErrRange 
TIFFReadDirEntryErrPsdif 
TIFFReadDirEntryErrSizesan 
TIFFReadDirEntryErrAlloc 

Definition at line 56 of file tif_dirread.c.

Function Documentation

◆ _TIFFFetchStrileValue()

static int _TIFFFetchStrileValue ( TIFF tif,
uint32  strile,
TIFFDirEntry dirent,
uint64 **  parray 
)
static

Definition at line 6143 of file tif_dirread.c.

6147 {
6148  static const char module[] = "_TIFFFetchStrileValue";
6149  TIFFDirectory *td = &tif->tif_dir;
6150  if( strile >= dirent->tdir_count )
6151  {
6152  return 0;
6153  }
6154  if( strile >= td->td_stripoffsetbyteallocsize )
6155  {
6156  uint32 nStripArrayAllocBefore = td->td_stripoffsetbyteallocsize;
6157  uint32 nStripArrayAllocNew;
6158  uint64 nArraySize64;
6159  size_t nArraySize;
6160  uint64* offsetArray;
6161  uint64* bytecountArray;
6162 
6163  if( strile > 1000000 )
6164  {
6165  uint64 filesize = TIFFGetFileSize(tif);
6166  /* Avoid excessive memory allocation attempt */
6167  /* For such a big blockid we need at least a TIFF_LONG per strile */
6168  /* for the offset array. */
6169  if( strile > filesize / sizeof(uint32) )
6170  {
6171  TIFFErrorExt(tif->tif_clientdata, module, "File too short");
6172  return 0;
6173  }
6174  }
6175 
6176  if( td->td_stripoffsetbyteallocsize == 0 &&
6177  td->td_nstrips < 1024 * 1024 )
6178  {
6179  nStripArrayAllocNew = td->td_nstrips;
6180  }
6181  else
6182  {
6183 #define TIFF_MAX(a,b) (((a)>(b)) ? (a) : (b))
6184 #define TIFF_MIN(a,b) (((a)<(b)) ? (a) : (b))
6185  nStripArrayAllocNew = TIFF_MAX(strile + 1, 1024U * 512U );
6186  if( nStripArrayAllocNew < 0xFFFFFFFFU / 2 )
6187  nStripArrayAllocNew *= 2;
6188  nStripArrayAllocNew = TIFF_MIN(nStripArrayAllocNew, td->td_nstrips);
6189  }
6190  assert( strile < nStripArrayAllocNew );
6191  nArraySize64 = (uint64)sizeof(uint64) * nStripArrayAllocNew;
6192  nArraySize = (size_t)(nArraySize64);
6193 #if SIZEOF_SIZE_T == 4
6194  if( nArraySize != nArraySize64 )
6195  {
6197  "Cannot allocate strip offset and bytecount arrays");
6198  return 0;
6199  }
6200 #endif
6201  offsetArray = (uint64*)(
6202  _TIFFrealloc( td->td_stripoffset_p, nArraySize ) );
6203  bytecountArray = (uint64*)(
6204  _TIFFrealloc( td->td_stripbytecount_p, nArraySize ) );
6205  if( offsetArray )
6206  td->td_stripoffset_p = offsetArray;
6207  if( bytecountArray )
6208  td->td_stripbytecount_p = bytecountArray;
6209  if( offsetArray && bytecountArray )
6210  {
6211  td->td_stripoffsetbyteallocsize = nStripArrayAllocNew;
6212  /* Initialize new entries to ~0 / -1 */
6213  memset(td->td_stripoffset_p + nStripArrayAllocBefore,
6214  0xFF,
6215  (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );
6216  memset(td->td_stripbytecount_p + nStripArrayAllocBefore,
6217  0xFF,
6218  (td->td_stripoffsetbyteallocsize - nStripArrayAllocBefore) * sizeof(uint64) );
6219  }
6220  else
6221  {
6223  "Cannot allocate strip offset and bytecount arrays");
6225  td->td_stripoffset_p = NULL;
6227  td->td_stripbytecount_p = NULL;
6229  }
6230  }
6231  if( *parray == NULL || strile >= td->td_stripoffsetbyteallocsize )
6232  return 0;
6233 
6234  if( ~((*parray)[strile]) == 0 )
6235  {
6236  if( !_TIFFPartialReadStripArray( tif, dirent, strile, *parray ) )
6237  {
6238  (*parray)[strile] = 0;
6239  return 0;
6240  }
6241  }
6242 
6243  return 1;
6244 }
unsigned long long uint64
Definition: platform.h:18
unsigned int uint32
Definition: types.h:32
#define U(x)
Definition: wordpad.c:45
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
#define assert(x)
Definition: debug.h:53
#define TIFF_MIN(a, b)
thandle_t tif_clientdata
Definition: tiffiop.h:207
Definition: fatfs.h:198
smooth NULL
Definition: ftsmooth.c:416
__kernel_size_t size_t
Definition: linux.h:237
uint32 td_nstrips
Definition: tif_dir.h:100
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
void * _TIFFrealloc(void *p, tmsize_t s)
Definition: tif_unix.c:332
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:241
TIFFDirectory tif_dir
Definition: tiffiop.h:151
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
uint32 td_stripoffsetbyteallocsize
Definition: tif_dir.h:103
#define TIFF_MAX(a, b)
void _TIFFfree(void *p)
Definition: tif_unix.c:326
#define memset(x, y, z)
Definition: compat.h:39
static int _TIFFPartialReadStripArray(TIFF *tif, TIFFDirEntry *dirent, int strile, uint64 *panVals)
Definition: tif_dirread.c:6002

Referenced by _TIFFGetStrileOffsetOrByteCountValue().

◆ _TIFFFillStriles()

int _TIFFFillStriles ( TIFF tif)

Definition at line 6320 of file tif_dirread.c.

6321 {
6322  return _TIFFFillStrilesInternal( tif, 1 );
6323 }
static int _TIFFFillStrilesInternal(TIFF *tif, int loadStripByteCount)
Definition: tif_dirread.c:6325

Referenced by _TIFFGetStrileOffsetOrByteCountValue(), _TIFFVGetField(), TIFFReadDirectory(), TIFFWriteCheck(), and TIFFWriteDirectorySec().

◆ _TIFFFillStrilesInternal()

static int _TIFFFillStrilesInternal ( TIFF tif,
int  loadStripByteCount 
)
static

Definition at line 6325 of file tif_dirread.c.

6326 {
6327  register TIFFDirectory *td = &tif->tif_dir;
6328  int return_value = 1;
6329 
6330  /* Do not do anything if TIFF_DEFERSTRILELOAD is not set */
6331  if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) || (tif->tif_flags&TIFF_CHOPPEDUPARRAYS) != 0 )
6332  return 1;
6333 
6334  if( tif->tif_flags&TIFF_LAZYSTRILELOAD )
6335  {
6336  /* In case of lazy loading, reload completely the arrays */
6339  td->td_stripoffset_p = NULL;
6340  td->td_stripbytecount_p = NULL;
6342  tif->tif_flags &= ~TIFF_LAZYSTRILELOAD;
6343  }
6344 
6345  /* If stripoffset array is already loaded, exit with success */
6346  if( td->td_stripoffset_p != NULL )
6347  return 1;
6348 
6349  /* If tdir_count was cancelled, then we already got there, but in error */
6350  if( td->td_stripoffset_entry.tdir_count == 0 )
6351  return 0;
6352 
6353  if (!TIFFFetchStripThing(tif,&(td->td_stripoffset_entry),
6354  td->td_nstrips,&td->td_stripoffset_p))
6355  {
6356  return_value = 0;
6357  }
6358 
6359  if (loadStripByteCount &&
6361  td->td_nstrips,&td->td_stripbytecount_p))
6362  {
6363  return_value = 0;
6364  }
6365 
6366  _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
6367  _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
6368 
6369 #ifdef STRIPBYTECOUNTSORTED_UNUSED
6370  if (tif->tif_dir.td_nstrips > 1 && return_value == 1 ) {
6371  uint32 strip;
6372 
6373  tif->tif_dir.td_stripbytecountsorted = 1;
6374  for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {
6375  if (tif->tif_dir.td_stripoffset_p[strip - 1] >
6376  tif->tif_dir.td_stripoffset_p[strip]) {
6377  tif->tif_dir.td_stripbytecountsorted = 0;
6378  break;
6379  }
6380  }
6381  }
6382 #endif
6383 
6384  return return_value;
6385 }
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
unsigned int uint32
Definition: types.h:32
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
#define TIFF_LAZYSTRILELOAD
Definition: tiffiop.h:144
static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32 nstrips, uint64 **lpp)
Definition: tif_dirread.c:5649
TIFFDirEntry td_stripbytecount_entry
Definition: tif_dir.h:108
uint32 tif_flags
Definition: tiffiop.h:119
smooth NULL
Definition: ftsmooth.c:416
uint32 td_nstrips
Definition: tif_dir.h:100
uint64 tdir_count
Definition: tif_dir.h:55
#define TIFF_DEFERSTRILELOAD
Definition: tiffiop.h:143
TIFFDirectory tif_dir
Definition: tiffiop.h:151
TIFFDirEntry td_stripoffset_entry
Definition: tif_dir.h:107
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
uint32 td_stripoffsetbyteallocsize
Definition: tif_dir.h:103
#define TIFF_CHOPPEDUPARRAYS
Definition: tiffiop.h:145
void _TIFFfree(void *p)
Definition: tif_unix.c:326

Referenced by _TIFFFillStriles(), and EstimateStripByteCounts().

◆ _TIFFGetMaxColorChannels()

static int _TIFFGetMaxColorChannels ( uint16  photometric)
static

Definition at line 3502 of file tif_dirread.c.

3503 {
3504  switch (photometric) {
3505  case PHOTOMETRIC_PALETTE:
3508  return 1;
3509  case PHOTOMETRIC_YCBCR:
3510  case PHOTOMETRIC_RGB:
3511  case PHOTOMETRIC_CIELAB:
3512  case PHOTOMETRIC_LOGLUV:
3513  case PHOTOMETRIC_ITULAB:
3514  case PHOTOMETRIC_ICCLAB:
3515  return 3;
3516  case PHOTOMETRIC_SEPARATED:
3517  case PHOTOMETRIC_MASK:
3518  return 4;
3519  case PHOTOMETRIC_LOGL:
3520  case PHOTOMETRIC_CFA:
3521  default:
3522  return 0;
3523  }
3524 }
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:202
#define PHOTOMETRIC_SEPARATED
Definition: tiff.h:201
#define PHOTOMETRIC_CIELAB
Definition: tiff.h:203
#define PHOTOMETRIC_LOGL
Definition: tiff.h:207
#define PHOTOMETRIC_LOGLUV
Definition: tiff.h:208
#define PHOTOMETRIC_ICCLAB
Definition: tiff.h:204
#define PHOTOMETRIC_ITULAB
Definition: tiff.h:205
#define PHOTOMETRIC_CFA
Definition: tiff.h:206
#define PHOTOMETRIC_RGB
Definition: tiff.h:198
#define PHOTOMETRIC_MINISWHITE
Definition: tiff.h:196
#define PHOTOMETRIC_PALETTE
Definition: tiff.h:199
#define PHOTOMETRIC_MINISBLACK
Definition: tiff.h:197
#define PHOTOMETRIC_MASK
Definition: tiff.h:200

Referenced by TIFFReadDirectory().

◆ _TIFFGetStrileOffsetOrByteCountValue()

static uint64 _TIFFGetStrileOffsetOrByteCountValue ( TIFF tif,
uint32  strile,
TIFFDirEntry dirent,
uint64 **  parray,
int pbErr 
)
static

Definition at line 6246 of file tif_dirread.c.

6250 {
6251  TIFFDirectory *td = &tif->tif_dir;
6252  if( pbErr )
6253  *pbErr = 0;
6255  {
6256  if( !(tif->tif_flags&TIFF_LAZYSTRILELOAD) ||
6257  /* If the values may fit in the toff_long/toff_long8 member */
6258  /* then use _TIFFFillStriles to simplify _TIFFFetchStrileValue */
6259  dirent->tdir_count <= 4 )
6260  {
6261  if( !_TIFFFillStriles(tif) )
6262  {
6263  if( pbErr )
6264  *pbErr = 1;
6265  /* Do not return, as we want this function to always */
6266  /* return the same value if called several times with */
6267  /* the same arguments */
6268  }
6269  }
6270  else
6271  {
6272  if( !_TIFFFetchStrileValue(tif, strile, dirent, parray) )
6273  {
6274  if( pbErr )
6275  *pbErr = 1;
6276  return 0;
6277  }
6278  }
6279  }
6280  if( *parray == NULL || strile >= td->td_nstrips )
6281  {
6282  if( pbErr )
6283  *pbErr = 1;
6284  return 0;
6285  }
6286  return (*parray)[strile];
6287 }
Definition: fatfs.h:198
#define TIFF_LAZYSTRILELOAD
Definition: tiffiop.h:144
uint32 tif_flags
Definition: tiffiop.h:119
smooth NULL
Definition: ftsmooth.c:416
uint32 td_nstrips
Definition: tif_dir.h:100
static int _TIFFFetchStrileValue(TIFF *tif, uint32 strile, TIFFDirEntry *dirent, uint64 **parray)
Definition: tif_dirread.c:6143
#define TIFF_DEFERSTRILELOAD
Definition: tiffiop.h:143
TIFFDirectory tif_dir
Definition: tiffiop.h:151
#define TIFF_CHOPPEDUPARRAYS
Definition: tiffiop.h:145
int _TIFFFillStriles(TIFF *tif)
Definition: tif_dirread.c:6320

Referenced by TIFFGetStrileByteCountWithErr(), and TIFFGetStrileOffsetWithErr().

◆ _TIFFPartialReadStripArray()

static int _TIFFPartialReadStripArray ( TIFF tif,
TIFFDirEntry dirent,
int  strile,
uint64 panVals 
)
static

Definition at line 6002 of file tif_dirread.c.

6004 {
6005  static const char module[] = "_TIFFPartialReadStripArray";
6006 #define IO_CACHE_PAGE_SIZE 4096
6007 
6008  size_t sizeofval;
6009  const int bSwab = (tif->tif_flags & TIFF_SWAB) != 0;
6010  int sizeofvalint;
6011  uint64 nBaseOffset;
6012  uint64 nOffset;
6013  uint64 nOffsetStartPage;
6014  uint64 nOffsetEndPage;
6015  tmsize_t nToRead;
6016  tmsize_t nRead;
6017  uint64 nLastStripOffset;
6018  int iStartBefore;
6019  int i;
6020  const uint32 arraySize = tif->tif_dir.td_stripoffsetbyteallocsize;
6021  unsigned char buffer[2 * IO_CACHE_PAGE_SIZE];
6022 
6023  assert( dirent->tdir_count > 4 );
6024 
6025  if( dirent->tdir_type == TIFF_SHORT )
6026  {
6027  sizeofval = sizeof(uint16);
6028  }
6029  else if( dirent->tdir_type == TIFF_LONG )
6030  {
6031  sizeofval = sizeof(uint32);
6032  }
6033  else if( dirent->tdir_type == TIFF_LONG8 )
6034  {
6035  sizeofval = sizeof(uint64);
6036  }
6037  else
6038  {
6040  "Invalid type for [Strip|Tile][Offset/ByteCount] tag");
6041  panVals[strile] = 0;
6042  return 0;
6043  }
6044  sizeofvalint = (int)(sizeofval);
6045 
6046  if( tif->tif_flags&TIFF_BIGTIFF )
6047  {
6048  uint64 offset = dirent->tdir_offset.toff_long8;
6049  if( bSwab )
6051  nBaseOffset = offset;
6052  }
6053  else
6054  {
6055  uint32 offset = dirent->tdir_offset.toff_long;
6056  if( bSwab )
6057  TIFFSwabLong(&offset);
6058  nBaseOffset = offset;
6059  }
6060  /* To avoid later unsigned integer overflows */
6061  if( nBaseOffset > (uint64)TIFF_INT64_MAX )
6062  {
6064  "Cannot read offset/size for strile %d", strile);
6065  panVals[strile] = 0;
6066  return 0;
6067  }
6068  nOffset = nBaseOffset + sizeofval * strile;
6069  nOffsetStartPage =
6070  (nOffset / IO_CACHE_PAGE_SIZE) * IO_CACHE_PAGE_SIZE;
6071  nOffsetEndPage = nOffsetStartPage + IO_CACHE_PAGE_SIZE;
6072 
6073  if( nOffset + sizeofval > nOffsetEndPage )
6074  nOffsetEndPage += IO_CACHE_PAGE_SIZE;
6075 #undef IO_CACHE_PAGE_SIZE
6076 
6077  nLastStripOffset = nBaseOffset + arraySize * sizeofval;
6078  if( nLastStripOffset < nOffsetEndPage )
6079  nOffsetEndPage = nLastStripOffset;
6080  if( nOffsetStartPage >= nOffsetEndPage )
6081  {
6083  "Cannot read offset/size for strile %d", strile);
6084  panVals[strile] = 0;
6085  return 0;
6086  }
6087  if (!SeekOK(tif,nOffsetStartPage))
6088  {
6089  panVals[strile] = 0;
6090  return 0;
6091  }
6092 
6093  nToRead = (tmsize_t)(nOffsetEndPage - nOffsetStartPage);
6094  nRead = TIFFReadFile(tif, buffer, nToRead);
6095  if( nRead < nToRead )
6096  {
6098  "Cannot read offset/size for strile around ~%d", strile);
6099  return 0;
6100  }
6101  iStartBefore = -(int)((nOffset - nOffsetStartPage) / sizeofval);
6102  if( strile + iStartBefore < 0 )
6103  iStartBefore = -strile;
6104  for( i = iStartBefore;
6105  (uint32)(strile + i) < arraySize &&
6106  _TIFFUnsanitizedAddUInt64AndInt(nOffset, (i + 1) * sizeofvalint) <= nOffsetEndPage;
6107  ++i )
6108  {
6109  if( sizeofval == sizeof(uint16) )
6110  {
6111  uint16 val;
6112  memcpy(&val,
6113  buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint,
6114  sizeof(val));
6115  if( bSwab )
6116  TIFFSwabShort(&val);
6117  panVals[strile + i] = val;
6118  }
6119  else if( sizeofval == sizeof(uint32) )
6120  {
6121  uint32 val;
6122  memcpy(&val,
6123  buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint,
6124  sizeof(val));
6125  if( bSwab )
6126  TIFFSwabLong(&val);
6127  panVals[strile + i] = val;
6128  }
6129  else
6130  {
6131  uint64 val;
6132  memcpy(&val,
6133  buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint,
6134  sizeof(val));
6135  if( bSwab )
6136  TIFFSwabLong8(&val);
6137  panVals[strile + i] = val;
6138  }
6139  }
6140  return 1;
6141 }
unsigned long long uint64
Definition: platform.h:18
#define TIFF_INT64_MAX
Definition: tif_dirread.c:46
unsigned int uint32
Definition: types.h:32
GLintptr offset
Definition: glext.h:5920
#define assert(x)
Definition: debug.h:53
GLuint buffer
Definition: glext.h:5915
thandle_t tif_clientdata
Definition: tiffiop.h:207
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64 _TIFFUnsanitizedAddUInt64AndInt(uint64 a, int b)
Definition: tif_dirread.c:5992
Definition: fatfs.h:198
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define TIFF_BIGTIFF
Definition: tiffiop.h:138
#define TIFF_SWAB
Definition: tiffiop.h:126
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
#define IO_CACHE_PAGE_SIZE
uint32 tif_flags
Definition: tiffiop.h:119
GLuint GLfloat * val
Definition: glext.h:7180
void TIFFSwabShort(uint16 *wp)
Definition: tif_swab.c:34
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
unsigned short uint16
Definition: types.h:30
TIFFDirectory tif_dir
Definition: tiffiop.h:151
#define SeekOK(tif, off)
Definition: tiffiop.h:256
uint32 td_stripoffsetbyteallocsize
Definition: tif_dir.h:103
#define TIFFReadFile(tif, buf, size)
Definition: tiffiop.h:233
void TIFFSwabLong8(uint64 *lp)
Definition: tif_swab.c:57
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by _TIFFFetchStrileValue().

◆ _TIFFUnsanitizedAddUInt64AndInt()

static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64 _TIFFUnsanitizedAddUInt64AndInt ( uint64  a,
int  b 
)
static

Definition at line 5992 of file tif_dirread.c.

5993 {
5994  return a + b;
5995 }
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by _TIFFPartialReadStripArray().

◆ allocChoppedUpStripArrays()

static void allocChoppedUpStripArrays ( TIFF tif,
uint32  nstrips,
uint64  stripbytes,
uint32  rowsperstrip 
)
static

Definition at line 5752 of file tif_dirread.c.

5754 {
5755  TIFFDirectory *td = &tif->tif_dir;
5756  uint64 bytecount;
5757  uint64 offset;
5758  uint64 last_offset;
5759  uint64 last_bytecount;
5760  uint32 i;
5761  uint64 *newcounts;
5762  uint64 *newoffsets;
5763 
5764  offset = TIFFGetStrileOffset(tif, 0);
5765  last_offset = TIFFGetStrileOffset(tif, td->td_nstrips-1);
5766  last_bytecount = TIFFGetStrileByteCount(tif, td->td_nstrips-1);
5767  if( last_offset > TIFF_UINT64_MAX - last_bytecount ||
5768  last_offset + last_bytecount < offset )
5769  {
5770  return;
5771  }
5772  bytecount = last_offset + last_bytecount - offset;
5773 
5774  newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
5775  "for chopped \"StripByteCounts\" array");
5776  newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
5777  "for chopped \"StripOffsets\" array");
5778  if (newcounts == NULL || newoffsets == NULL) {
5779  /*
5780  * Unable to allocate new strip information, give up and use
5781  * the original one strip information.
5782  */
5783  if (newcounts != NULL)
5784  _TIFFfree(newcounts);
5785  if (newoffsets != NULL)
5786  _TIFFfree(newoffsets);
5787  return;
5788  }
5789 
5790  /*
5791  * Fill the strip information arrays with new bytecounts and offsets
5792  * that reflect the broken-up format.
5793  */
5794  for (i = 0; i < nstrips; i++)
5795  {
5796  if (stripbytes > bytecount)
5797  stripbytes = bytecount;
5798  newcounts[i] = stripbytes;
5799  newoffsets[i] = stripbytes ? offset : 0;
5800  offset += stripbytes;
5801  bytecount -= stripbytes;
5802  }
5803 
5804  /*
5805  * Replace old single strip info with multi-strip info.
5806  */
5807  td->td_stripsperimage = td->td_nstrips = nstrips;
5808  TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
5809 
5812  td->td_stripbytecount_p = newcounts;
5813  td->td_stripoffset_p = newoffsets;
5814 #ifdef STRIPBYTECOUNTSORTED_UNUSED
5815  td->td_stripbytecountsorted = 1;
5816 #endif
5818 }
unsigned long long uint64
Definition: platform.h:18
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:233
unsigned int uint32
Definition: types.h:32
#define TIFF_UINT64_MAX
Definition: tiffiop.h:91
GLintptr offset
Definition: glext.h:5920
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:121
uint32 td_stripsperimage
Definition: tif_dir.h:99
uint32 tif_flags
Definition: tiffiop.h:119
smooth NULL
Definition: ftsmooth.c:416
uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6290
uint32 td_nstrips
Definition: tif_dir.h:100
TIFFDirectory tif_dir
Definition: tiffiop.h:151
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
#define TIFF_CHOPPEDUPARRAYS
Definition: tiffiop.h:145
void _TIFFfree(void *p)
Definition: tif_unix.c:326
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:807
uint64 TIFFGetStrileByteCount(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6305

Referenced by ChopUpSingleUncompressedStrip(), and TryChopUpUncompressedBigTiff().

◆ ByteCountLooksBad()

static int ByteCountLooksBad ( TIFF tif)
static

Definition at line 3526 of file tif_dirread.c.

3527 {
3528  /*
3529  * Assume we have wrong StripByteCount value (in case
3530  * of single strip) in following cases:
3531  * - it is equal to zero along with StripOffset;
3532  * - it is larger than file itself (in case of uncompressed
3533  * image);
3534  * - it is smaller than the size of the bytes per row
3535  * multiplied on the number of rows. The last case should
3536  * not be checked in the case of writing new image,
3537  * because we may do not know the exact strip size
3538  * until the whole image will be written and directory
3539  * dumped out.
3540  */
3541  uint64 bytecount = TIFFGetStrileByteCount(tif, 0);
3542  uint64 offset = TIFFGetStrileOffset(tif, 0);
3543  uint64 filesize;
3544 
3545  if( offset == 0 )
3546  return 0;
3547  if (bytecount == 0)
3548  return 1;
3549  if ( tif->tif_dir.td_compression != COMPRESSION_NONE )
3550  return 0;
3551  filesize = TIFFGetFileSize(tif);
3552  if( offset <= filesize && bytecount > filesize - offset )
3553  return 1;
3554  if( tif->tif_mode == O_RDONLY )
3555  {
3556  uint64 scanlinesize = TIFFScanlineSize64(tif);
3557  if( tif->tif_dir.td_imagelength > 0 &&
3558  scanlinesize > TIFF_UINT64_MAX / tif->tif_dir.td_imagelength )
3559  {
3560  return 1;
3561  }
3562  if( bytecount < scanlinesize * tif->tif_dir.td_imagelength)
3563  return 1;
3564  }
3565  return 0;
3566 }
unsigned long long uint64
Definition: platform.h:18
#define TIFF_UINT64_MAX
Definition: tiffiop.h:91
GLintptr offset
Definition: glext.h:5920
uint64 TIFFScanlineSize64(TIFF *tif)
Definition: tif_strip.c:257
int tif_mode
Definition: tiffiop.h:118
uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6290
uint32 td_imagelength
Definition: tif_dir.h:72
#define COMPRESSION_NONE
Definition: tiff.h:158
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:241
TIFFDirectory tif_dir
Definition: tiffiop.h:151
uint16 td_compression
Definition: tif_dir.h:77
uint64 TIFFGetStrileByteCount(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6305
#define O_RDONLY
Definition: acwin.h:108

Referenced by TIFFReadDirectory().

◆ CheckDirCount()

static int CheckDirCount ( TIFF tif,
TIFFDirEntry dir,
uint32  count 
)
static

Definition at line 4679 of file tif_dirread.c.

4680 {
4681  if ((uint64)count > dir->tdir_count) {
4682  const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag);
4684  "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag ignored",
4685  fip ? fip->field_name : "unknown tagname",
4686  dir->tdir_count, count);
4687  return (0);
4688  } else if ((uint64)count < dir->tdir_count) {
4689  const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag);
4691  "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag trimmed",
4692  fip ? fip->field_name : "unknown tagname",
4693  dir->tdir_count, count);
4694  dir->tdir_count = count;
4695  return (1);
4696  }
4697  return (1);
4698 }
unsigned long long uint64
Definition: platform.h:18
#define TIFF_UINT64_FORMAT
Definition: tif_config.h:52
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
GLuint GLuint GLsizei count
Definition: gl.h:1545
thandle_t tif_clientdata
Definition: tiffiop.h:207
char * tif_name
Definition: tiffiop.h:116
char * field_name
Definition: tif_dir.h:293
unsigned int dir
Definition: maze.c:112
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558

Referenced by TIFFReadCustomDirectory().

◆ ChopUpSingleUncompressedStrip()

static void ChopUpSingleUncompressedStrip ( TIFF tif)
static

Definition at line 5828 of file tif_dirread.c.

5829 {
5830  register TIFFDirectory *td = &tif->tif_dir;
5831  uint64 bytecount;
5832  uint64 offset;
5833  uint32 rowblock;
5834  uint64 rowblockbytes;
5835  uint64 stripbytes;
5836  uint32 nstrips;
5837  uint32 rowsperstrip;
5838 
5839  bytecount = TIFFGetStrileByteCount(tif, 0);
5840  /* On a newly created file, just re-opened to be filled, we */
5841  /* don't want strip chop to trigger as it is going to cause issues */
5842  /* later ( StripOffsets and StripByteCounts improperly filled) . */
5843  if( bytecount == 0 && tif->tif_mode != O_RDONLY )
5844  return;
5845  offset = TIFFGetStrileByteCount(tif, 0);
5847  if ((td->td_photometric == PHOTOMETRIC_YCBCR)&&
5848  (!isUpSampled(tif)))
5849  rowblock = td->td_ycbcrsubsampling[1];
5850  else
5851  rowblock = 1;
5852  rowblockbytes = TIFFVTileSize64(tif, rowblock);
5853  /*
5854  * Make the rows hold at least one scanline, but fill specified amount
5855  * of data if possible.
5856  */
5857  if (rowblockbytes > STRIP_SIZE_DEFAULT) {
5858  stripbytes = rowblockbytes;
5859  rowsperstrip = rowblock;
5860  } else if (rowblockbytes > 0 ) {
5861  uint32 rowblocksperstrip;
5862  rowblocksperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowblockbytes);
5863  rowsperstrip = rowblocksperstrip * rowblock;
5864  stripbytes = rowblocksperstrip * rowblockbytes;
5865  }
5866  else
5867  return;
5868 
5869  /*
5870  * never increase the number of rows per strip
5871  */
5872  if (rowsperstrip >= td->td_rowsperstrip)
5873  return;
5874  nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip);
5875  if( nstrips == 0 )
5876  return;
5877 
5878  /* If we are going to allocate a lot of memory, make sure that the */
5879  /* file is as big as needed */
5880  if( tif->tif_mode == O_RDONLY &&
5881  nstrips > 1000000 &&
5882  (offset >= TIFFGetFileSize(tif) ||
5883  stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
5884  {
5885  return;
5886  }
5887 
5888  allocChoppedUpStripArrays(tif, nstrips, stripbytes, rowsperstrip);
5889 }
unsigned long long uint64
Definition: platform.h:18
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:202
#define TIFFhowmany_32(x, y)
Definition: tiffiop.h:264
#define STRIP_SIZE_DEFAULT
Definition: tiffiop.h:69
unsigned int uint32
Definition: types.h:32
GLintptr offset
Definition: glext.h:5920
#define assert(x)
Definition: debug.h:53
#define isUpSampled(tif)
Definition: tiffiop.h:232
int tif_mode
Definition: tiffiop.h:118
uint16 td_planarconfig
Definition: tif_dir.h:89
uint32 td_imagelength
Definition: tif_dir.h:72
uint16 td_photometric
Definition: tif_dir.h:78
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:241
uint32 td_rowsperstrip
Definition: tif_dir.h:83
uint16 td_ycbcrsubsampling[2]
Definition: tif_dir.h:112
TIFFDirectory tif_dir
Definition: tiffiop.h:151
uint64 TIFFVTileSize64(TIFF *tif, uint32 nrows)
Definition: tif_tile.c:192
uint64 TIFFGetStrileByteCount(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6305
static void allocChoppedUpStripArrays(TIFF *tif, uint32 nstrips, uint64 stripbytes, uint32 rowsperstrip)
Definition: tif_dirread.c:5752
#define PLANARCONFIG_CONTIG
Definition: tiff.h:240
#define O_RDONLY
Definition: acwin.h:108

Referenced by TIFFReadDirectory().

◆ EstimateStripByteCounts()

static int EstimateStripByteCounts ( TIFF tif,
TIFFDirEntry dir,
uint16  dircount 
)
static

Definition at line 4509 of file tif_dirread.c.

4510 {
4511  static const char module[] = "EstimateStripByteCounts";
4512 
4513  TIFFDirEntry *dp;
4514  TIFFDirectory *td = &tif->tif_dir;
4515  uint32 strip;
4516 
4517  /* Do not try to load stripbytecount as we will compute it */
4518  if( !_TIFFFillStrilesInternal( tif, 0 ) )
4519  return -1;
4520 
4521  if (td->td_stripbytecount_p)
4523  td->td_stripbytecount_p = (uint64*)
4525  "for \"StripByteCounts\" array");
4526  if( td->td_stripbytecount_p == NULL )
4527  return -1;
4528 
4529  if (td->td_compression != COMPRESSION_NONE) {
4530  uint64 space;
4531  uint64 filesize;
4532  uint16 n;
4533  filesize = TIFFGetFileSize(tif);
4534  if (!(tif->tif_flags&TIFF_BIGTIFF))
4535  space=sizeof(TIFFHeaderClassic)+2+dircount*12+4;
4536  else
4537  space=sizeof(TIFFHeaderBig)+8+dircount*20+8;
4538  /* calculate amount of space used by indirect values */
4539  for (dp = dir, n = dircount; n > 0; n--, dp++)
4540  {
4541  uint32 typewidth;
4542  uint64 datasize;
4543  typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);
4544  if (typewidth == 0) {
4546  "Cannot determine size of unknown tag type %d",
4547  dp->tdir_type);
4548  return -1;
4549  }
4550  if( dp->tdir_count > TIFF_UINT64_MAX / typewidth )
4551  return -1;
4552  datasize=(uint64)typewidth*dp->tdir_count;
4553  if (!(tif->tif_flags&TIFF_BIGTIFF))
4554  {
4555  if (datasize<=4)
4556  datasize=0;
4557  }
4558  else
4559  {
4560  if (datasize<=8)
4561  datasize=0;
4562  }
4563  if( space > TIFF_UINT64_MAX - datasize )
4564  return -1;
4565  space+=datasize;
4566  }
4567  if( filesize < space )
4568  /* we should perhaps return in error ? */
4569  space = filesize;
4570  else
4571  space = filesize - space;
4573  space /= td->td_samplesperpixel;
4574  for (strip = 0; strip < td->td_nstrips; strip++)
4575  td->td_stripbytecount_p[strip] = space;
4576  /*
4577  * This gross hack handles the case were the offset to
4578  * the last strip is past the place where we think the strip
4579  * should begin. Since a strip of data must be contiguous,
4580  * it's safe to assume that we've overestimated the amount
4581  * of data in the strip and trim this number back accordingly.
4582  */
4583  strip--;
4584  if (td->td_stripoffset_p[strip] > TIFF_UINT64_MAX - td->td_stripbytecount_p[strip])
4585  return -1;
4586  if (td->td_stripoffset_p[strip]+td->td_stripbytecount_p[strip] > filesize) {
4587  if( td->td_stripoffset_p[strip] >= filesize ) {
4588  /* Not sure what we should in that case... */
4589  td->td_stripbytecount_p[strip] = 0;
4590  } else {
4591  td->td_stripbytecount_p[strip] = filesize - td->td_stripoffset_p[strip];
4592  }
4593  }
4594  } else if (isTiled(tif)) {
4595  uint64 bytespertile = TIFFTileSize64(tif);
4596 
4597  for (strip = 0; strip < td->td_nstrips; strip++)
4598  td->td_stripbytecount_p[strip] = bytespertile;
4599  } else {
4600  uint64 rowbytes = TIFFScanlineSize64(tif);
4601  uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage;
4602  for (strip = 0; strip < td->td_nstrips; strip++)
4603  {
4604  if( rowbytes > 0 && rowsperstrip > TIFF_UINT64_MAX / rowbytes )
4605  return -1;
4606  td->td_stripbytecount_p[strip] = rowbytes * rowsperstrip;
4607  }
4608  }
4610  if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
4611  td->td_rowsperstrip = td->td_imagelength;
4612  return 1;
4613 }
unsigned long long uint64
Definition: platform.h:18
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned int uint32
Definition: types.h:32
#define TIFF_UINT64_MAX
Definition: tiffiop.h:91
GLdouble n
Definition: glext.h:7729
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
thandle_t tif_clientdata
Definition: tiffiop.h:207
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:197
#define TIFF_BIGTIFF
Definition: tiffiop.h:138
#define FIELD_STRIPBYTECOUNTS
Definition: tif_dir.h:161
uint64 TIFFScanlineSize64(TIFF *tif)
Definition: tif_strip.c:257
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:121
uint32 td_stripsperimage
Definition: tif_dir.h:99
uint32 tif_flags
Definition: tiffiop.h:119
smooth NULL
Definition: ftsmooth.c:416
static SIZE_T datasize
Definition: asm.c:30
uint16 td_planarconfig
Definition: tif_dir.h:89
unsigned int dir
Definition: maze.c:112
uint32 td_nstrips
Definition: tif_dir.h:100
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint32 td_imagelength
Definition: tif_dir.h:72
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:196
uint64 TIFFTileSize64(TIFF *tif)
Definition: tif_tile.c:252
#define FIELD_ROWSPERSTRIP
Definition: tif_dir.h:155
uint64 tdir_count
Definition: tif_dir.h:55
#define COMPRESSION_NONE
Definition: tiff.h:158
static const WCHAR space[]
Definition: ConsoleCP.c:24
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:241
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:241
#define isTiled(tif)
Definition: tiffiop.h:229
int TIFFDataWidth(TIFFDataType type)
Definition: tif_dirinfo.c:438
uint32 td_rowsperstrip
Definition: tif_dir.h:83
unsigned short uint16
Definition: types.h:30
TIFFDirectory tif_dir
Definition: tiffiop.h:151
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
static int _TIFFFillStrilesInternal(TIFF *tif, int loadStripByteCount)
Definition: tif_dirread.c:6325
uint16 td_samplesperpixel
Definition: tif_dir.h:82
uint16 td_compression
Definition: tif_dir.h:77
void _TIFFfree(void *p)
Definition: tif_unix.c:326
TIFFDataType
Definition: tiff.h:123
uint16 tdir_type
Definition: tif_dir.h:54

Referenced by TIFFReadDirectory().

◆ MissingRequired()

static void MissingRequired ( TIFF tif,
const char tagname 
)
static

Definition at line 4616 of file tif_dirread.c.

4617 {
4618  static const char module[] = "MissingRequired";
4619 
4621  "TIFF directory is missing required \"%s\" field",
4622  tagname);
4623 }
thandle_t tif_clientdata
Definition: tiffiop.h:207
static char tagname[200]
Definition: rgenstat.c:63
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65

Referenced by TIFFReadDirectory().

◆ TIFFCheckDirOffset()

static int TIFFCheckDirOffset ( TIFF tif,
uint64  diroff 
)
static

Definition at line 4632 of file tif_dirread.c.

4633 {
4634  uint16 n;
4635 
4636  if (diroff == 0) /* no more directories */
4637  return 0;
4638  if (tif->tif_dirnumber == 65535) {
4639  TIFFErrorExt(tif->tif_clientdata, "TIFFCheckDirOffset",
4640  "Cannot handle more than 65535 TIFF directories");
4641  return 0;
4642  }
4643 
4644  for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) {
4645  if (tif->tif_dirlist[n] == diroff)
4646  return 0;
4647  }
4648 
4649  tif->tif_dirnumber++;
4650 
4651  if (tif->tif_dirlist == NULL || tif->tif_dirnumber > tif->tif_dirlistsize) {
4652  uint64* new_dirlist;
4653 
4654  /*
4655  * XXX: Reduce memory allocation granularity of the dirlist
4656  * array.
4657  */
4658  new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist,
4659  tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list");
4660  if (!new_dirlist)
4661  return 0;
4662  if( tif->tif_dirnumber >= 32768 )
4663  tif->tif_dirlistsize = 65535;
4664  else
4665  tif->tif_dirlistsize = 2 * tif->tif_dirnumber;
4666  tif->tif_dirlist = new_dirlist;
4667  }
4668 
4669  tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff;
4670 
4671  return 1;
4672 }
unsigned long long uint64
Definition: platform.h:18
void * _TIFFCheckRealloc(TIFF *tif, void *buffer, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:97
GLdouble n
Definition: glext.h:7729
thandle_t tif_clientdata
Definition: tiffiop.h:207
smooth NULL
Definition: ftsmooth.c:416
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
uint64 * tif_dirlist
Definition: tiffiop.h:148
uint16 tif_dirnumber
Definition: tiffiop.h:150
unsigned short uint16
Definition: types.h:30
uint16 tif_dirlistsize
Definition: tiffiop.h:149

Referenced by TIFFReadDirectory().

◆ TIFFCvtIEEEDoubleToNative()

void TIFFCvtIEEEDoubleToNative ( TIFF ,
uint32  ,
double  
)

◆ TIFFCvtIEEEFloatToNative()

void TIFFCvtIEEEFloatToNative ( TIFF ,
uint32  ,
float  
)

◆ TIFFFetchDirectory()

static uint16 TIFFFetchDirectory ( TIFF tif,
uint64  diroff,
TIFFDirEntry **  pdir,
uint64 nextdiroff 
)
static

Definition at line 4706 of file tif_dirread.c.

4708 {
4709  static const char module[] = "TIFFFetchDirectory";
4710 
4711  void* origdir;
4712  uint16 dircount16;
4713  uint32 dirsize;
4714  TIFFDirEntry* dir;
4715  uint8* ma;
4716  TIFFDirEntry* mb;
4717  uint16 n;
4718 
4719  assert(pdir);
4720 
4721  tif->tif_diroff = diroff;
4722  if (nextdiroff)
4723  *nextdiroff = 0;
4724  if (!isMapped(tif)) {
4725  if (!SeekOK(tif, tif->tif_diroff)) {
4727  "%s: Seek error accessing TIFF directory",
4728  tif->tif_name);
4729  return 0;
4730  }
4731  if (!(tif->tif_flags&TIFF_BIGTIFF))
4732  {
4733  if (!ReadOK(tif, &dircount16, sizeof (uint16))) {
4735  "%s: Can not read TIFF directory count",
4736  tif->tif_name);
4737  return 0;
4738  }
4739  if (tif->tif_flags & TIFF_SWAB)
4740  TIFFSwabShort(&dircount16);
4741  if (dircount16>4096)
4742  {
4744  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4745  return 0;
4746  }
4747  dirsize = 12;
4748  } else {
4749  uint64 dircount64;
4750  if (!ReadOK(tif, &dircount64, sizeof (uint64))) {
4752  "%s: Can not read TIFF directory count",
4753  tif->tif_name);
4754  return 0;
4755  }
4756  if (tif->tif_flags & TIFF_SWAB)
4757  TIFFSwabLong8(&dircount64);
4758  if (dircount64>4096)
4759  {
4761  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4762  return 0;
4763  }
4764  dircount16 = (uint16)dircount64;
4765  dirsize = 20;
4766  }
4767  origdir = _TIFFCheckMalloc(tif, dircount16,
4768  dirsize, "to read TIFF directory");
4769  if (origdir == NULL)
4770  return 0;
4771  if (!ReadOK(tif, origdir, (tmsize_t)(dircount16*dirsize))) {
4773  "%.100s: Can not read TIFF directory",
4774  tif->tif_name);
4775  _TIFFfree(origdir);
4776  return 0;
4777  }
4778  /*
4779  * Read offset to next directory for sequential scans if
4780  * needed.
4781  */
4782  if (nextdiroff)
4783  {
4784  if (!(tif->tif_flags&TIFF_BIGTIFF))
4785  {
4786  uint32 nextdiroff32;
4787  if (!ReadOK(tif, &nextdiroff32, sizeof(uint32)))
4788  nextdiroff32 = 0;
4789  if (tif->tif_flags&TIFF_SWAB)
4790  TIFFSwabLong(&nextdiroff32);
4791  *nextdiroff=nextdiroff32;
4792  } else {
4793  if (!ReadOK(tif, nextdiroff, sizeof(uint64)))
4794  *nextdiroff = 0;
4795  if (tif->tif_flags&TIFF_SWAB)
4796  TIFFSwabLong8(nextdiroff);
4797  }
4798  }
4799  } else {
4800  tmsize_t m;
4801  tmsize_t off;
4802  if (tif->tif_diroff > (uint64)TIFF_INT64_MAX)
4803  {
4804  TIFFErrorExt(tif->tif_clientdata,module,"Can not read TIFF directory count");
4805  return(0);
4806  }
4807  off = (tmsize_t) tif->tif_diroff;
4808 
4809  /*
4810  * Check for integer overflow when validating the dir_off,
4811  * otherwise a very high offset may cause an OOB read and
4812  * crash the client. Make two comparisons instead of
4813  *
4814  * off + sizeof(uint16) > tif->tif_size
4815  *
4816  * to avoid overflow.
4817  */
4818  if (!(tif->tif_flags&TIFF_BIGTIFF))
4819  {
4820  m=off+sizeof(uint16);
4821  if ((m<off)||(m<(tmsize_t)sizeof(uint16))||(m>tif->tif_size)) {
4823  "Can not read TIFF directory count");
4824  return 0;
4825  } else {
4826  _TIFFmemcpy(&dircount16, tif->tif_base + off,
4827  sizeof(uint16));
4828  }
4829  off += sizeof (uint16);
4830  if (tif->tif_flags & TIFF_SWAB)
4831  TIFFSwabShort(&dircount16);
4832  if (dircount16>4096)
4833  {
4835  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4836  return 0;
4837  }
4838  dirsize = 12;
4839  }
4840  else
4841  {
4842  uint64 dircount64;
4843  m=off+sizeof(uint64);
4844  if ((m<off)||(m<(tmsize_t)sizeof(uint64))||(m>tif->tif_size)) {
4846  "Can not read TIFF directory count");
4847  return 0;
4848  } else {
4849  _TIFFmemcpy(&dircount64, tif->tif_base + off,
4850  sizeof(uint64));
4851  }
4852  off += sizeof (uint64);
4853  if (tif->tif_flags & TIFF_SWAB)
4854  TIFFSwabLong8(&dircount64);
4855  if (dircount64>4096)
4856  {
4858  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4859  return 0;
4860  }
4861  dircount16 = (uint16)dircount64;
4862  dirsize = 20;
4863  }
4864  if (dircount16 == 0 )
4865  {
4867  "Sanity check on directory count failed, zero tag directories not supported");
4868  return 0;
4869  }
4870  origdir = _TIFFCheckMalloc(tif, dircount16,
4871  dirsize,
4872  "to read TIFF directory");
4873  if (origdir == NULL)
4874  return 0;
4875  m=off+dircount16*dirsize;
4876  if ((m<off)||(m<(tmsize_t)(dircount16*dirsize))||(m>tif->tif_size)) {
4878  "Can not read TIFF directory");
4879  _TIFFfree(origdir);
4880  return 0;
4881  } else {
4882  _TIFFmemcpy(origdir, tif->tif_base + off,
4883  dircount16 * dirsize);
4884  }
4885  if (nextdiroff) {
4886  off += dircount16 * dirsize;
4887  if (!(tif->tif_flags&TIFF_BIGTIFF))
4888  {
4889  uint32 nextdiroff32;
4890  m=off+sizeof(uint32);
4891  if ((m<off)||(m<(tmsize_t)sizeof(uint32))||(m>tif->tif_size))
4892  nextdiroff32 = 0;
4893  else
4894  _TIFFmemcpy(&nextdiroff32, tif->tif_base + off,
4895  sizeof (uint32));
4896  if (tif->tif_flags&TIFF_SWAB)
4897  TIFFSwabLong(&nextdiroff32);
4898  *nextdiroff = nextdiroff32;
4899  }
4900  else
4901  {
4902  m=off+sizeof(uint64);
4903  if ((m<off)||(m<(tmsize_t)sizeof(uint64))||(m>tif->tif_size))
4904  *nextdiroff = 0;
4905  else
4906  _TIFFmemcpy(nextdiroff, tif->tif_base + off,
4907  sizeof (uint64));
4908  if (tif->tif_flags&TIFF_SWAB)
4909  TIFFSwabLong8(nextdiroff);
4910  }
4911  }
4912  }
4913  dir = (TIFFDirEntry*)_TIFFCheckMalloc(tif, dircount16,
4914  sizeof(TIFFDirEntry),
4915  "to read TIFF directory");
4916  if (dir==0)
4917  {
4918  _TIFFfree(origdir);
4919  return 0;
4920  }
4921  ma=(uint8*)origdir;
4922  mb=dir;
4923  for (n=0; n<dircount16; n++)
4924  {
4925  mb->tdir_ignore = FALSE;
4926  if (tif->tif_flags&TIFF_SWAB)
4927  TIFFSwabShort((uint16*)ma);
4928  mb->tdir_tag=*(uint16*)ma;
4929  ma+=sizeof(uint16);
4930  if (tif->tif_flags&TIFF_SWAB)
4931  TIFFSwabShort((uint16*)ma);
4932  mb->tdir_type=*(uint16*)ma;
4933  ma+=sizeof(uint16);
4934  if (!(tif->tif_flags&TIFF_BIGTIFF))
4935  {
4936  if (tif->tif_flags&TIFF_SWAB)
4937  TIFFSwabLong((uint32*)ma);
4938  mb->tdir_count=(uint64)(*(uint32*)ma);
4939  ma+=sizeof(uint32);
4940  mb->tdir_offset.toff_long8=0;
4941  *(uint32*)(&mb->tdir_offset)=*(uint32*)ma;
4942  ma+=sizeof(uint32);
4943  }
4944  else
4945  {
4946  if (tif->tif_flags&TIFF_SWAB)
4947  TIFFSwabLong8((uint64*)ma);
4948  mb->tdir_count=TIFFReadUInt64(ma);
4949  ma+=sizeof(uint64);
4951  ma+=sizeof(uint64);
4952  }
4953  mb++;
4954  }
4955  _TIFFfree(origdir);
4956  *pdir = dir;
4957  return dircount16;
4958 }
unsigned long long uint64
Definition: platform.h:18
uint8 tdir_ignore
Definition: tif_dir.h:61
uint8 * tif_base
Definition: tiffiop.h:202
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define TIFF_INT64_MAX
Definition: tif_dirread.c:46
unsigned int uint32
Definition: types.h:32
GLdouble n
Definition: glext.h:7729
#define assert(x)
Definition: debug.h:53
thandle_t tif_clientdata
Definition: tiffiop.h:207
char * tif_name
Definition: tiffiop.h:116
const GLfloat * m
Definition: glext.h:10848
#define TIFF_BIGTIFF
Definition: tiffiop.h:138
#define TIFF_SWAB
Definition: tiffiop.h:126
#define FALSE
Definition: types.h:117
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:121
uint32 tif_flags
Definition: tiffiop.h:119
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
#define isMapped(tif)
Definition: tiffiop.h:230
void TIFFSwabShort(uint16 *wp)
Definition: tif_swab.c:34
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint16 tdir_tag
Definition: tif_dir.h:53
unsigned char uint8
Definition: types.h:28
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
uint64 tdir_count
Definition: tif_dir.h:55
uint64 tif_diroff
Definition: tiffiop.h:146
tmsize_t tif_size
Definition: tiffiop.h:203
static uint64 TIFFReadUInt64(const uint8 *value)
Definition: tif_dirread.c:186
union TIFFDirEntry::@3425 tdir_offset
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
unsigned short uint16
Definition: types.h:30
#define SeekOK(tif, off)
Definition: tiffiop.h:256
#define ReadOK(tif, buf, size)
Definition: tiffiop.h:252
void _TIFFfree(void *p)
Definition: tif_unix.c:326
uint64 toff_long8
Definition: tif_dir.h:59
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
void TIFFSwabLong8(uint64 *lp)
Definition: tif_swab.c:57
uint16 tdir_type
Definition: tif_dir.h:54
off
Definition: i386-dis.c:3909

Referenced by TIFFReadCustomDirectory(), and TIFFReadDirectory().

◆ TIFFFetchNormalTag()

static int TIFFFetchNormalTag ( TIFF tif,
TIFFDirEntry dp,
int  recover 
)
static

Definition at line 4964 of file tif_dirread.c.

4965 {
4966  static const char module[] = "TIFFFetchNormalTag";
4967  enum TIFFReadDirEntryErr err;
4968  uint32 fii;
4969  const TIFFField* fip = NULL;
4971  if( fii == FAILED_FII )
4972  {
4973  TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag",
4974  "No definition found for tag %d",
4975  dp->tdir_tag);
4976  return 0;
4977  }
4978  fip=tif->tif_fields[fii];
4979  assert(fip != NULL); /* should not happen */
4980  assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't arrive here but deal with this in specialized code */
4981  assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't arrive here as this is only the case for pseudo-tags */
4983  switch (fip->set_field_type)
4984  {
4985  case TIFF_SETGET_UNDEFINED:
4986  break;
4987  case TIFF_SETGET_ASCII:
4988  {
4989  uint8* data;
4990  assert(fip->field_passcount==0);
4993  {
4994  uint32 mb = 0;
4995  int n;
4996  if (data != NULL)
4997  {
4998  uint8* ma = data;
4999  while (mb<(uint32)dp->tdir_count)
5000  {
5001  if (*ma==0)
5002  break;
5003  ma++;
5004  mb++;
5005  }
5006  }
5007  if (mb+1<(uint32)dp->tdir_count)
5008  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);
5009  else if (mb+1>(uint32)dp->tdir_count)
5010  {
5011  uint8* o;
5012  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte",fip->field_name);
5013  if ((uint32)dp->tdir_count+1!=dp->tdir_count+1)
5014  o=NULL;
5015  else
5016  o=_TIFFmalloc((uint32)dp->tdir_count+1);
5017  if (o==NULL)
5018  {
5019  if (data!=NULL)
5020  _TIFFfree(data);
5021  return(0);
5022  }
5024  o[(uint32)dp->tdir_count]=0;
5025  if (data!=0)
5026  _TIFFfree(data);
5027  data=o;
5028  }
5029  n=TIFFSetField(tif,dp->tdir_tag,data);
5030  if (data!=0)
5031  _TIFFfree(data);
5032  if (!n)
5033  return(0);
5034  }
5035  }
5036  break;
5037  case TIFF_SETGET_UINT8:
5038  {
5039  uint8 data=0;
5040  assert(fip->field_readcount==1);
5041  assert(fip->field_passcount==0);
5042  err=TIFFReadDirEntryByte(tif,dp,&data);
5044  {
5045  if (!TIFFSetField(tif,dp->tdir_tag,data))
5046  return(0);
5047  }
5048  }
5049  break;
5050  case TIFF_SETGET_UINT16:
5051  {
5052  uint16 data;
5053  assert(fip->field_readcount==1);
5054  assert(fip->field_passcount==0);
5055  err=TIFFReadDirEntryShort(tif,dp,&data);
5057  {
5058  if (!TIFFSetField(tif,dp->tdir_tag,data))
5059  return(0);
5060  }
5061  }
5062  break;
5063  case TIFF_SETGET_UINT32:
5064  {
5065  uint32 data;
5066  assert(fip->field_readcount==1);
5067  assert(fip->field_passcount==0);
5068  err=TIFFReadDirEntryLong(tif,dp,&data);
5070  {
5071  if (!TIFFSetField(tif,dp->tdir_tag,data))
5072  return(0);
5073  }
5074  }
5075  break;
5076  case TIFF_SETGET_UINT64:
5077  {
5078  uint64 data;
5079  assert(fip->field_readcount==1);
5080  assert(fip->field_passcount==0);
5081  err=TIFFReadDirEntryLong8(tif,dp,&data);
5083  {
5084  if (!TIFFSetField(tif,dp->tdir_tag,data))
5085  return(0);
5086  }
5087  }
5088  break;
5089  case TIFF_SETGET_FLOAT:
5090  {
5091  float data;
5092  assert(fip->field_readcount==1);
5093  assert(fip->field_passcount==0);
5094  err=TIFFReadDirEntryFloat(tif,dp,&data);
5096  {
5097  if (!TIFFSetField(tif,dp->tdir_tag,data))
5098  return(0);
5099  }
5100  }
5101  break;
5102  case TIFF_SETGET_DOUBLE:
5103  {
5104  double data;
5105  assert(fip->field_readcount==1);
5106  assert(fip->field_passcount==0);
5107  err=TIFFReadDirEntryDouble(tif,dp,&data);
5109  {
5110  if (!TIFFSetField(tif,dp->tdir_tag,data))
5111  return(0);
5112  }
5113  }
5114  break;
5115  case TIFF_SETGET_IFD8:
5116  {
5117  uint64 data;
5118  assert(fip->field_readcount==1);
5119  assert(fip->field_passcount==0);
5120  err=TIFFReadDirEntryIfd8(tif,dp,&data);
5122  {
5123  if (!TIFFSetField(tif,dp->tdir_tag,data))
5124  return(0);
5125  }
5126  }
5127  break;
5129  {
5130  uint16* data;
5131  assert(fip->field_readcount==2);
5132  assert(fip->field_passcount==0);
5133  if (dp->tdir_count!=2) {
5134  TIFFWarningExt(tif->tif_clientdata,module,
5135  "incorrect count for field \"%s\", expected 2, got %d",
5136  fip->field_name,(int)dp->tdir_count);
5137  return(0);
5138  }
5141  {
5142  int m;
5143  m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]);
5144  _TIFFfree(data);
5145  if (!m)
5146  return(0);
5147  }
5148  }
5149  break;
5150  case TIFF_SETGET_C0_UINT8:
5151  {
5152  uint8* data;
5153  assert(fip->field_readcount>=1);
5154  assert(fip->field_passcount==0);
5155  if (dp->tdir_count!=(uint64)fip->field_readcount) {
5156  TIFFWarningExt(tif->tif_clientdata,module,
5157  "incorrect count for field \"%s\", expected %d, got %d",
5158  fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count);
5159  return 0;
5160  }
5161  else
5162  {
5165  {
5166  int m;
5167  m=TIFFSetField(tif,dp->tdir_tag,data);
5168  if (data!=0)
5169  _TIFFfree(data);
5170  if (!m)
5171  return(0);
5172  }
5173  }
5174  }
5175  break;
5176  case TIFF_SETGET_C0_UINT16:
5177  {
5178  uint16* data;
5179  assert(fip->field_readcount>=1);
5180  assert(fip->field_passcount==0);
5181  if (dp->tdir_count!=(uint64)fip->field_readcount)
5182  /* corrupt file */;
5183  else
5184  {
5187  {
5188  int m;
5189  m=TIFFSetField(tif,dp->tdir_tag,data);
5190  if (data!=0)
5191  _TIFFfree(data);
5192  if (!m)
5193  return(0);
5194  }
5195  }
5196  }
5197  break;
5198  case TIFF_SETGET_C0_UINT32:
5199  {
5200  uint32* data;
5201  assert(fip->field_readcount>=1);
5202  assert(fip->field_passcount==0);
5203  if (dp->tdir_count!=(uint64)fip->field_readcount)
5204  /* corrupt file */;
5205  else
5206  {
5209  {
5210  int m;
5211  m=TIFFSetField(tif,dp->tdir_tag,data);
5212  if (data!=0)
5213  _TIFFfree(data);
5214  if (!m)
5215  return(0);
5216  }
5217  }
5218  }
5219  break;
5220  case TIFF_SETGET_C0_FLOAT:
5221  {
5222  float* data;
5223  assert(fip->field_readcount>=1);
5224  assert(fip->field_passcount==0);
5225  if (dp->tdir_count!=(uint64)fip->field_readcount)
5226  /* corrupt file */;
5227  else
5228  {
5231  {
5232  int m;
5233  m=TIFFSetField(tif,dp->tdir_tag,data);
5234  if (data!=0)
5235  _TIFFfree(data);
5236  if (!m)
5237  return(0);
5238  }
5239  }
5240  }
5241  break;
5242  case TIFF_SETGET_C16_ASCII:
5243  {
5244  uint8* data;
5246  assert(fip->field_passcount==1);
5247  if (dp->tdir_count>0xFFFF)
5249  else
5250  {
5253  {
5254  int m;
5255  if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
5256  {
5257  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
5258  data[dp->tdir_count-1] = '\0';
5259  }
5260  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5261  if (data!=0)
5262  _TIFFfree(data);
5263  if (!m)
5264  return(0);
5265  }
5266  }
5267  }
5268  break;
5269  case TIFF_SETGET_C16_UINT8:
5270  {
5271  uint8* data;
5273  assert(fip->field_passcount==1);
5274  if (dp->tdir_count>0xFFFF)
5276  else
5277  {
5280  {
5281  int m;
5282  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5283  if (data!=0)
5284  _TIFFfree(data);
5285  if (!m)
5286  return(0);
5287  }
5288  }
5289  }
5290  break;
5292  {
5293  uint16* data;
5295  assert(fip->field_passcount==1);
5296  if (dp->tdir_count>0xFFFF)
5298  else
5299  {
5302  {
5303  int m;
5304  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5305  if (data!=0)
5306  _TIFFfree(data);
5307  if (!m)
5308  return(0);
5309  }
5310  }
5311  }
5312  break;
5314  {
5315  uint32* data;
5317  assert(fip->field_passcount==1);
5318  if (dp->tdir_count>0xFFFF)
5320  else
5321  {
5324  {
5325  int m;
5326  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5327  if (data!=0)
5328  _TIFFfree(data);
5329  if (!m)
5330  return(0);
5331  }
5332  }
5333  }
5334  break;
5336  {
5337  uint64* data;
5339  assert(fip->field_passcount==1);
5340  if (dp->tdir_count>0xFFFF)
5342  else
5343  {
5346  {
5347  int m;
5348  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5349  if (data!=0)
5350  _TIFFfree(data);
5351  if (!m)
5352  return(0);
5353  }
5354  }
5355  }
5356  break;
5357  case TIFF_SETGET_C16_FLOAT:
5358  {
5359  float* data;
5361  assert(fip->field_passcount==1);
5362  if (dp->tdir_count>0xFFFF)
5364  else
5365  {
5368  {
5369  int m;
5370  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5371  if (data!=0)
5372  _TIFFfree(data);
5373  if (!m)
5374  return(0);
5375  }
5376  }
5377  }
5378  break;
5380  {
5381  double* data;
5383  assert(fip->field_passcount==1);
5384  if (dp->tdir_count>0xFFFF)
5386  else
5387  {
5390  {
5391  int m;
5392  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5393  if (data!=0)
5394  _TIFFfree(data);
5395  if (!m)
5396  return(0);
5397  }
5398  }
5399  }
5400  break;
5401  case TIFF_SETGET_C16_IFD8:
5402  {
5403  uint64* data;
5405  assert(fip->field_passcount==1);
5406  if (dp->tdir_count>0xFFFF)
5408  else
5409  {
5412  {
5413  int m;
5414  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5415  if (data!=0)
5416  _TIFFfree(data);
5417  if (!m)
5418  return(0);
5419  }
5420  }
5421  }
5422  break;
5423  case TIFF_SETGET_C32_ASCII:
5424  {
5425  uint8* data;
5427  assert(fip->field_passcount==1);
5430  {
5431  int m;
5432  if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
5433  {
5434  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
5435  data[dp->tdir_count-1] = '\0';
5436  }
5437  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5438  if (data!=0)
5439  _TIFFfree(data);
5440  if (!m)
5441  return(0);
5442  }
5443  }
5444  break;
5445  case TIFF_SETGET_C32_UINT8:
5446  {
5447  uint8* data;
5449  assert(fip->field_passcount==1);
5452  {
5453  int m;
5454  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5455  if (data!=0)
5456  _TIFFfree(data);
5457  if (!m)
5458  return(0);
5459  }
5460  }
5461  break;
5462  case TIFF_SETGET_C32_SINT8:
5463  {
5464  int8* data = NULL;
5466  assert(fip->field_passcount==1);
5469  {
5470  int m;
5471  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5472  if (data!=0)
5473  _TIFFfree(data);
5474  if (!m)
5475  return(0);
5476  }
5477  }
5478  break;
5480  {
5481  uint16* data;
5483  assert(fip->field_passcount==1);
5486  {
5487  int m;
5488  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5489  if (data!=0)
5490  _TIFFfree(data);
5491  if (!m)
5492  return(0);
5493  }
5494  }
5495  break;
5497  {
5498  int16* data = NULL;
5500  assert(fip->field_passcount==1);
5503  {
5504  int m;
5505  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5506  if (data!=0)
5507  _TIFFfree(data);
5508  if (!m)
5509  return(0);
5510  }
5511  }
5512  break;
5514  {
5515  uint32* data;
5517  assert(fip->field_passcount==1);
5520  {
5521  int m;
5522  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5523  if (data!=0)
5524  _TIFFfree(data);
5525  if (!m)
5526  return(0);
5527  }
5528  }
5529  break;
5531  {
5532  int32* data = NULL;
5534  assert(fip->field_passcount==1);
5537  {
5538  int m;
5539  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5540  if (data!=0)
5541  _TIFFfree(data);
5542  if (!m)
5543  return(0);
5544  }
5545  }
5546  break;
5548  {
5549  uint64* data;
5551  assert(fip->field_passcount==1);
5554  {
5555  int m;
5556  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5557  if (data!=0)
5558  _TIFFfree(data);
5559  if (!m)
5560  return(0);
5561  }
5562  }
5563  break;
5565  {
5566  int64* data = NULL;
5568  assert(fip->field_passcount==1);
5571  {
5572  int m;
5573  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5574  if (data!=0)
5575  _TIFFfree(data);
5576  if (!m)
5577  return(0);
5578  }
5579  }
5580  break;
5581  case TIFF_SETGET_C32_FLOAT:
5582  {
5583  float* data;
5585  assert(fip->field_passcount==1);
5588  {
5589  int m;
5590  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5591  if (data!=0)
5592  _TIFFfree(data);
5593  if (!m)
5594  return(0);
5595  }
5596  }
5597  break;
5599  {
5600  double* data;
5602  assert(fip->field_passcount==1);
5605  {
5606  int m;
5607  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5608  if (data!=0)
5609  _TIFFfree(data);
5610  if (!m)
5611  return(0);
5612  }
5613  }
5614  break;
5615  case TIFF_SETGET_C32_IFD8:
5616  {
5617  uint64* data;
5619  assert(fip->field_passcount==1);
5622  {
5623  int m;
5624  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5625  if (data!=0)
5626  _TIFFfree(data);
5627  if (!m)
5628  return(0);
5629  }
5630  }
5631  break;
5632  default:
5633  assert(0); /* we should never get here */
5634  break;
5635  }
5637  {
5638  TIFFReadDirEntryOutputErr(tif,err,module,fip->field_name,recover);
5639  return(0);
5640  }
5641  return(1);
5642 }
unsigned long long uint64
Definition: platform.h:18
return
Definition: dirsup.c:529
#define TIFF_VARIABLE
Definition: tiffio.h:308
static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF *tif, TIFFDirEntry *direntry, int8 **value)
Definition: tif_dirread.c:1115
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4358
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
TIFFReadDirEntryErr
Definition: tif_dirread.c:56
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
Definition: tif_dirread.c:2530
unsigned int uint32
Definition: types.h:32
GLdouble n
Definition: glext.h:7729
#define assert(x)
Definition: debug.h:53
static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray(TIFF *tif, TIFFDirEntry *direntry, uint32 **value)
Definition: tif_dirread.c:1633
thandle_t tif_clientdata
Definition: tiffiop.h:207
long long int64
Definition: platform.h:13
const GLfloat * m
Definition: glext.h:10848
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array(TIFF *tif, TIFFDirEntry *direntry, int64 **value)
Definition: tif_dirread.c:2135
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF *tif, TIFFDirEntry *direntry, uint32 *value)
Definition: tif_dirread.c:378
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
Definition: tif_dirread.c:749
char * field_name
Definition: tif_dir.h:293
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF *tif, TIFFDirEntry *direntry, int32 **value)
Definition: tif_dirread.c:1802
static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF *tif, TIFFDirEntry *direntry, uint8 **value)
Definition: tif_dirread.c:934
#define FAILED_FII
Definition: tif_dirread.c:41
smooth NULL
Definition: ftsmooth.c:416
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array(TIFF *tif, TIFFDirEntry *direntry, uint64 **value)
Definition: tif_dirread.c:2767
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF *tif, TIFFDirEntry *direntry, uint64 **value)
Definition: tif_dirread.c:2130
unsigned char field_passcount
Definition: tif_dir.h:292
static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF *tif, TIFFDirEntry *direntry, double *value)
Definition: tif_dirread.c:652
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint16 tdir_tag
Definition: tif_dir.h:53
unsigned char uint8
Definition: types.h:28
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
uint64 tdir_count
Definition: tif_dir.h:55
static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray(TIFF *tif, TIFFDirEntry *direntry, int16 **value)
Definition: tif_dirread.c:1466
#define err(...)
TIFFField ** tif_fields
Definition: tiffiop.h:216
#define TIFF_VARIABLE2
Definition: tiffio.h:310
TIFFSetGetFieldType set_field_type
Definition: tif_dir.h:288
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF *tif, TIFFDirEntry *direntry, float **value)
Definition: tif_dirread.c:2285
unsigned short uint16
Definition: types.h:30
short int16
Definition: platform.h:11
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat(TIFF *tif, TIFFDirEntry *direntry, float *value)
Definition: tif_dirread.c:539
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:292
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
Definition: tif_dirread.c:461
long int32
Definition: platform.h:12
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3410
void _TIFFfree(void *p)
Definition: tif_unix.c:326
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF *tif, TIFFDirEntry *direntry, uint16 **value)
Definition: tif_dirread.c:1294
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:807
static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF *tif, TIFFDirEntry *direntry, uint8 *value)
Definition: tif_dirread.c:202
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
char int8
Definition: platform.h:10
short field_readcount
Definition: tif_dir.h:284

Referenced by TIFFReadCustomDirectory(), and TIFFReadDirectory().

◆ TIFFFetchStripThing()

static int TIFFFetchStripThing ( TIFF tif,
TIFFDirEntry dir,
uint32  nstrips,
uint64 **  lpp 
)
static

Definition at line 5649 of file tif_dirread.c.

5650 {
5651  static const char module[] = "TIFFFetchStripThing";
5652  enum TIFFReadDirEntryErr err;
5653  uint64* data;
5656  {
5657  const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);
5658  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
5659  return(0);
5660  }
5661  if (dir->tdir_count<(uint64)nstrips)
5662  {
5663  uint64* resizeddata;
5664  const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);
5665  const char* pszMax = getenv("LIBTIFF_STRILE_ARRAY_MAX_RESIZE_COUNT");
5666  uint32 max_nstrips = 1000000;
5667  if( pszMax )
5668  max_nstrips = (uint32) atoi(pszMax);
5670  module,
5671  fip ? fip->field_name : "unknown tagname",
5672  ( nstrips <= max_nstrips ) );
5673 
5674  if( nstrips > max_nstrips )
5675  {
5676  _TIFFfree(data);
5677  return(0);
5678  }
5679 
5680  resizeddata=(uint64*)_TIFFCheckMalloc(tif,nstrips,sizeof(uint64),"for strip array");
5681  if (resizeddata==0) {
5682  _TIFFfree(data);
5683  return(0);
5684  }
5685  _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64));
5686  _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64));
5687  _TIFFfree(data);
5688  data=resizeddata;
5689  }
5690  *lpp=data;
5691  return(1);
5692 }
unsigned long long uint64
Definition: platform.h:18
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
TIFFReadDirEntryErr
Definition: tif_dirread.c:56
unsigned int uint32
Definition: types.h:32
char * field_name
Definition: tif_dir.h:293
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:121
unsigned int dir
Definition: maze.c:112
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558
#define err(...)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3410
void _TIFFfree(void *p)
Definition: tif_unix.c:326
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8ArrayWithLimit(TIFF *tif, TIFFDirEntry *direntry, uint64 **value, uint64 maxcount)
Definition: tif_dirread.c:1963
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344

Referenced by _TIFFFillStrilesInternal(), and TIFFReadDirectory().

◆ TIFFFetchSubjectDistance()

static int TIFFFetchSubjectDistance ( TIFF tif,
TIFFDirEntry dir 
)
static

Definition at line 5698 of file tif_dirread.c.

5699 {
5700  static const char module[] = "TIFFFetchSubjectDistance";
5701  enum TIFFReadDirEntryErr err;
5703  m.l=0;
5704  assert(sizeof(double)==8);
5705  assert(sizeof(uint64)==8);
5706  assert(sizeof(uint32)==4);
5707  if (dir->tdir_count!=1)
5709  else if (dir->tdir_type!=TIFF_RATIONAL)
5711  else
5712  {
5713  if (!(tif->tif_flags&TIFF_BIGTIFF))
5714  {
5715  uint32 offset;
5716  offset=*(uint32*)(&dir->tdir_offset);
5717  if (tif->tif_flags&TIFF_SWAB)
5718  TIFFSwabLong(&offset);
5719  err=TIFFReadDirEntryData(tif,offset,8,m.i);
5720  }
5721  else
5722  {
5723  m.l=dir->tdir_offset.toff_long8;
5725  }
5726  }
5728  {
5729  double n;
5730  if (tif->tif_flags&TIFF_SWAB)
5731  TIFFSwabArrayOfLong(m.i,2);
5732  if (m.i[0]==0)
5733  n=0.0;
5734  else if (m.i[0]==0xFFFFFFFF || m.i[1]==0)
5735  /*
5736  * XXX: Numerator 0xFFFFFFFF means that we have infinite
5737  * distance. Indicate that with a negative floating point
5738  * SubjectDistance value.
5739  */
5740  n=-1.0;
5741  else
5742  n=(double)m.i[0]/(double)m.i[1];
5743  return(TIFFSetField(tif,dir->tdir_tag,n));
5744  }
5745  else
5746  {
5747  TIFFReadDirEntryOutputErr(tif,err,module,"SubjectDistance",TRUE);
5748  return(0);
5749  }
5750 }
unsigned long long uint64
Definition: platform.h:18
TIFFReadDirEntryErr
Definition: tif_dirread.c:56
#define TRUE
Definition: types.h:120
unsigned int uint32
Definition: types.h:32
GLintptr offset
Definition: glext.h:5920
GLdouble n
Definition: glext.h:7729
#define assert(x)
Definition: debug.h:53
const GLfloat * m
Definition: glext.h:10848
#define TIFF_BIGTIFF
Definition: tiffiop.h:138
#define TIFF_SWAB
Definition: tiffiop.h:126
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
uint32 tif_flags
Definition: tiffiop.h:119
unsigned int dir
Definition: maze.c:112
void TIFFSwabArrayOfLong(register uint32 *lp, tmsize_t n)
Definition: tif_swab.c:103
static enum TIFFReadDirEntryErr TIFFReadDirEntryData(TIFF *tif, uint64 offset, tmsize_t size, void *dest)
Definition: tif_dirread.c:3386
#define err(...)
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3410
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:807

Referenced by TIFFReadCustomDirectory().

◆ TIFFGetStrileByteCount()

uint64 TIFFGetStrileByteCount ( TIFF tif,
uint32  strile 
)

◆ TIFFGetStrileByteCountWithErr()

uint64 TIFFGetStrileByteCountWithErr ( TIFF tif,
uint32  strile,
int pbErr 
)

Definition at line 6311 of file tif_dirread.c.

6312 {
6313  TIFFDirectory *td = &tif->tif_dir;
6314  return _TIFFGetStrileOffsetOrByteCountValue(tif, strile,
6315  &(td->td_stripbytecount_entry),
6316  &(td->td_stripbytecount_p), pbErr);
6317 }
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
static uint64 _TIFFGetStrileOffsetOrByteCountValue(TIFF *tif, uint32 strile, TIFFDirEntry *dirent, uint64 **parray, int *pbErr)
Definition: tif_dirread.c:6246
TIFFDirEntry td_stripbytecount_entry
Definition: tif_dir.h:108
TIFFDirectory tif_dir
Definition: tiffiop.h:151

Referenced by TIFFGetStrileByteCount().

◆ TIFFGetStrileOffset()

uint64 TIFFGetStrileOffset ( TIFF tif,
uint32  strile 
)

Definition at line 6290 of file tif_dirread.c.

6291 {
6292  return TIFFGetStrileOffsetWithErr(tif, strile, NULL);
6293 }
smooth NULL
Definition: ftsmooth.c:416
uint64 TIFFGetStrileOffsetWithErr(TIFF *tif, uint32 strile, int *pbErr)
Definition: tif_dirread.c:6296

Referenced by allocChoppedUpStripArrays(), ByteCountLooksBad(), TIFFFillStrip(), TIFFFillStripPartial(), TIFFFillTile(), TIFFPrintDirectory(), TIFFReadDirectory(), TIFFReadRawStrip1(), TIFFReadRawStripOrTile2(), TIFFReadRawTile1(), and TryChopUpUncompressedBigTiff().

◆ TIFFGetStrileOffsetWithErr()

uint64 TIFFGetStrileOffsetWithErr ( TIFF tif,
uint32  strile,
int pbErr 
)

Definition at line 6296 of file tif_dirread.c.

6297 {
6298  TIFFDirectory *td = &tif->tif_dir;
6299  return _TIFFGetStrileOffsetOrByteCountValue(tif, strile,
6300  &(td->td_stripoffset_entry),
6301  &(td->td_stripoffset_p), pbErr);
6302 }
static uint64 _TIFFGetStrileOffsetOrByteCountValue(TIFF *tif, uint32 strile, TIFFDirEntry *dirent, uint64 **parray, int *pbErr)
Definition: tif_dirread.c:6246
TIFFDirectory tif_dir
Definition: tiffiop.h:151
TIFFDirEntry td_stripoffset_entry
Definition: tif_dir.h:107
uint64 * td_stripoffset_p
Definition: tif_dir.h:101

Referenced by TIFFGetStrileOffset().

◆ TIFFReadCustomDirectory()

int TIFFReadCustomDirectory ( TIFF tif,
toff_t  diroff,
const TIFFFieldArray infoarray 
)

Definition at line 4394 of file tif_dirread.c.

4396 {
4397  static const char module[] = "TIFFReadCustomDirectory";
4398  TIFFDirEntry* dir;
4399  uint16 dircount;
4400  TIFFDirEntry* dp;
4401  uint16 di;
4402  const TIFFField* fip;
4403  uint32 fii;
4404  _TIFFSetupFields(tif, infoarray);
4405  dircount=TIFFFetchDirectory(tif,diroff,&dir,NULL);
4406  if (!dircount)
4407  {
4409  "Failed to read custom directory at offset " TIFF_UINT64_FORMAT,diroff);
4410  return 0;
4411  }
4412  TIFFFreeDirectory(tif);
4413  _TIFFmemset(&tif->tif_dir, 0, sizeof(TIFFDirectory));
4414  TIFFReadDirectoryCheckOrder(tif,dir,dircount);
4415  for (di=0, dp=dir; di<dircount; di++, dp++)
4416  {
4418  if (fii == FAILED_FII)
4419  {
4421  "Unknown field with tag %d (0x%x) encountered",
4422  dp->tdir_tag, dp->tdir_tag);
4423  if (!_TIFFMergeFields(tif, _TIFFCreateAnonField(tif,
4424  dp->tdir_tag,
4425  (TIFFDataType) dp->tdir_type),
4426  1)) {
4428  "Registering anonymous field with tag %d (0x%x) failed",
4429  dp->tdir_tag, dp->tdir_tag);
4430  dp->tdir_ignore = TRUE;
4431  } else {
4433  assert( fii != FAILED_FII );
4434  }
4435  }
4436  if (!dp->tdir_ignore)
4437  {
4438  fip=tif->tif_fields[fii];
4439  if (fip->field_bit==FIELD_IGNORE)
4440  dp->tdir_ignore = TRUE;
4441  else
4442  {
4443  /* check data type */
4444  while ((fip->field_type!=TIFF_ANY)&&(fip->field_type!=dp->tdir_type))
4445  {
4446  fii++;
4447  if ((fii==tif->tif_nfields)||
4448  (tif->tif_fields[fii]->field_tag!=(uint32)dp->tdir_tag))
4449  {
4450  fii=0xFFFF;
4451  break;
4452  }
4453  fip=tif->tif_fields[fii];
4454  }
4455  if (fii==0xFFFF)
4456  {
4458  "Wrong data type %d for \"%s\"; tag ignored",
4459  dp->tdir_type,fip->field_name);
4460  dp->tdir_ignore = TRUE;
4461  }
4462  else
4463  {
4464  /* check count if known in advance */
4465  if ((fip->field_readcount!=TIFF_VARIABLE)&&
4467  {
4468  uint32 expected;
4469  if (fip->field_readcount==TIFF_SPP)
4471  else
4473  if (!CheckDirCount(tif,dp,expected))
4474  dp->tdir_ignore = TRUE;
4475  }
4476  }
4477  }
4478  if (!dp->tdir_ignore) {
4479  switch (dp->tdir_tag)
4480  {
4482  (void)TIFFFetchSubjectDistance(tif, dp);
4483  break;
4484  default:
4485  (void)TIFFFetchNormalTag(tif, dp, TRUE);
4486  break;
4487  }
4488  } /*-- if (!dp->tdir_ignore) */
4489  }
4490  }
4491  if (dir)
4492  _TIFFfree(dir);
4493  return 1;
4494 }
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
#define FIELD_IGNORE
Definition: tif_dir.h:138
uint8 tdir_ignore
Definition: tif_dir.h:61
#define TIFF_VARIABLE
Definition: tiffio.h:308
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4358
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TIFF_UINT64_FORMAT
Definition: tif_config.h:52
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
TIFFField * _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type)
Definition: tif_dirinfo.c:634
#define TIFF_ANY
Definition: tiffio.h:307
static int CheckDirCount(TIFF *, TIFFDirEntry *, uint32)
Definition: tif_dirread.c:4679
#define TRUE
Definition: types.h:120
unsigned int uint32
Definition: types.h:32
static int TIFFFetchNormalTag(TIFF *, TIFFDirEntry *, int recover)
Definition: tif_dirread.c:4964
#define assert(x)
Definition: debug.h:53
thandle_t tif_clientdata
Definition: tiffiop.h:207
unsigned short field_bit
Definition: tif_dir.h:290
static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
Definition: tif_dirread.c:4324
char * field_name
Definition: tif_dir.h:293
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32 n)
Definition: tif_dirinfo.c:369
#define FAILED_FII
Definition: tif_dirread.c:41
smooth NULL
Definition: ftsmooth.c:416
size_t tif_nfields
Definition: tiffiop.h:217
unsigned int dir
Definition: maze.c:112
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1268
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Definition: tif_dirinfo.c:317
uint32 field_tag
Definition: tif_dir.h:283
uint16 tdir_tag
Definition: tif_dir.h:53
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define EXIFTAG_SUBJECTDISTANCE
Definition: tiff.h:643
TIFFField ** tif_fields
Definition: tiffiop.h:216
#define TIFF_VARIABLE2
Definition: tiffio.h:310
TIFFDataType field_type
Definition: tif_dir.h:286
#define TIFF_SPP
Definition: tiffio.h:309
unsigned short uint16
Definition: types.h:30
TIFFDirectory tif_dir
Definition: tiffiop.h:151
static int TIFFFetchSubjectDistance(TIFF *, TIFFDirEntry *)
Definition: tif_dirread.c:5698
uint16 td_samplesperpixel
Definition: tif_dir.h:82
void _TIFFfree(void *p)
Definition: tif_unix.c:326
static uint16 TIFFFetchDirectory(TIFF *tif, uint64 diroff, TIFFDirEntry **pdir, uint64 *nextdiroff)
Definition: tif_dirread.c:4706
BOOL expected
Definition: store.c:2063
TIFFDataType
Definition: tiff.h:123
uint16 tdir_type
Definition: tif_dir.h:54
short field_readcount
Definition: tif_dir.h:284

Referenced by TIFFReadEXIFDirectory().

◆ TIFFReadDirectory()

int TIFFReadDirectory ( TIFF tif)

Definition at line 3574 of file tif_dirread.c.

3575 {
3576  static const char module[] = "TIFFReadDirectory";
3577  TIFFDirEntry* dir;
3578  uint16 dircount;
3579  TIFFDirEntry* dp;
3580  uint16 di;
3581  const TIFFField* fip;
3582  uint32 fii=FAILED_FII;
3583  toff_t nextdiroff;
3584  int bitspersample_read = FALSE;
3585  int color_channels;
3586 
3587  tif->tif_diroff=tif->tif_nextdiroff;
3588  if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
3589  return 0; /* last offset or bad offset (IFD looping) */
3590  (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */
3591  tif->tif_curdir++;
3592  nextdiroff = tif->tif_nextdiroff;
3593  dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff);
3594  if (!dircount)
3595  {
3597  "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff);
3598  return 0;
3599  }
3600  TIFFReadDirectoryCheckOrder(tif,dir,dircount);
3601 
3602  /*
3603  * Mark duplicates of any tag to be ignored (bugzilla 1994)
3604  * to avoid certain pathological problems.
3605  */
3606  {
3607  TIFFDirEntry* ma;
3608  uint16 mb;
3609  for (ma=dir, mb=0; mb<dircount; ma++, mb++)
3610  {
3611  TIFFDirEntry* na;
3612  uint16 nb;
3613  for (na=ma+1, nb=mb+1; nb<dircount; na++, nb++)
3614  {
3615  if (ma->tdir_tag == na->tdir_tag) {
3616  na->tdir_ignore = TRUE;
3617  }
3618  }
3619  }
3620  }
3621 
3622  tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */
3623  tif->tif_flags &= ~TIFF_BUF4WRITE; /* reset before new dir */
3625 
3626  /* free any old stuff and reinit */
3627  TIFFFreeDirectory(tif);
3628  TIFFDefaultDirectory(tif);
3629  /*
3630  * Electronic Arts writes gray-scale TIFF files
3631  * without a PlanarConfiguration directory entry.
3632  * Thus we setup a default value here, even though
3633  * the TIFF spec says there is no default value.
3634  */
3636  /*
3637  * Setup default value and then make a pass over
3638  * the fields to check type and tag information,
3639  * and to extract info required to size data
3640  * structures. A second pass is made afterwards
3641  * to read in everything not taken in the first pass.
3642  * But we must process the Compression tag first
3643  * in order to merge in codec-private tag definitions (otherwise
3644  * we may get complaints about unknown tags). However, the
3645  * Compression tag may be dependent on the SamplesPerPixel
3646  * tag value because older TIFF specs permitted Compression
3647  * to be written as a SamplesPerPixel-count tag entry.
3648  * Thus if we don't first figure out the correct SamplesPerPixel
3649  * tag value then we may end up ignoring the Compression tag
3650  * value because it has an incorrect count value (if the
3651  * true value of SamplesPerPixel is not 1).
3652  */
3654  if (dp)
3655  {
3656  if (!TIFFFetchNormalTag(tif,dp,0))
3657  goto bad;
3658  dp->tdir_ignore = TRUE;
3659  }
3661  if (dp)
3662  {
3663  /*
3664  * The 5.0 spec says the Compression tag has one value, while
3665  * earlier specs say it has one value per sample. Because of
3666  * this, we accept the tag if one value is supplied with either
3667  * count.
3668  */
3669  uint16 value;
3670  enum TIFFReadDirEntryErr err;
3671  err=TIFFReadDirEntryShort(tif,dp,&value);
3675  {
3676  TIFFReadDirEntryOutputErr(tif,err,module,"Compression",0);
3677  goto bad;
3678  }
3680  goto bad;
3681  dp->tdir_ignore = TRUE;
3682  }
3683  else
3684  {
3686  goto bad;
3687  }
3688  /*
3689  * First real pass over the directory.
3690  */
3691  for (di=0, dp=dir; di<dircount; di++, dp++)
3692  {
3693  if (!dp->tdir_ignore)
3694  {
3696  if (fii == FAILED_FII)
3697  {
3699  "Unknown field with tag %d (0x%x) encountered",
3700  dp->tdir_tag,dp->tdir_tag);
3701  /* the following knowingly leaks the
3702  anonymous field structure */
3703  if (!_TIFFMergeFields(tif,
3705  dp->tdir_tag,
3706  (TIFFDataType) dp->tdir_type),
3707  1)) {
3709  module,
3710  "Registering anonymous field with tag %d (0x%x) failed",
3711  dp->tdir_tag,
3712  dp->tdir_tag);
3713  dp->tdir_ignore = TRUE;
3714  } else {
3716  assert(fii != FAILED_FII);
3717  }
3718  }
3719  }
3720  if (!dp->tdir_ignore)
3721  {
3722  fip=tif->tif_fields[fii];
3723  if (fip->field_bit==FIELD_IGNORE)
3724  dp->tdir_ignore = TRUE;
3725  else
3726  {
3727  switch (dp->tdir_tag)
3728  {
3729  case TIFFTAG_STRIPOFFSETS:
3731  case TIFFTAG_TILEOFFSETS:
3733  TIFFSetFieldBit(tif,fip->field_bit);
3734  break;
3735  case TIFFTAG_IMAGEWIDTH:
3736  case TIFFTAG_IMAGELENGTH:
3737  case TIFFTAG_IMAGEDEPTH:
3738  case TIFFTAG_TILELENGTH:
3739  case TIFFTAG_TILEWIDTH:
3740  case TIFFTAG_TILEDEPTH:
3741  case TIFFTAG_PLANARCONFIG:
3742  case TIFFTAG_ROWSPERSTRIP:
3743  case TIFFTAG_EXTRASAMPLES:
3744  if (!TIFFFetchNormalTag(tif,dp,0))
3745  goto bad;
3746  dp->tdir_ignore = TRUE;
3747  break;
3748  default:
3749  if( !_TIFFCheckFieldIsValidForCodec(tif, dp->tdir_tag) )
3750  dp->tdir_ignore = TRUE;
3751  break;
3752  }
3753  }
3754  }
3755  }
3756  /*
3757  * XXX: OJPEG hack.
3758  * If a) compression is OJPEG, b) planarconfig tag says it's separate,
3759  * c) strip offsets/bytecounts tag are both present and
3760  * d) both contain exactly one value, then we consistently find
3761  * that the buggy implementation of the buggy compression scheme
3762  * matches contig planarconfig best. So we 'fix-up' the tag here
3763  */
3766  {
3767  if (!_TIFFFillStriles(tif))
3768  goto bad;
3770  if ((dp!=0)&&(dp->tdir_count==1))
3771  {
3772  dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,
3774  if ((dp!=0)&&(dp->tdir_count==1))
3775  {
3778  "Planarconfig tag value assumed incorrect, "
3779  "assuming data is contig instead of chunky");
3780  }
3781  }
3782  }
3783  /*
3784  * Allocate directory structure and setup defaults.
3785  */
3787  {
3788  MissingRequired(tif,"ImageLength");
3789  goto bad;
3790  }
3791  /*
3792  * Setup appropriate structures (by strip or by tile)
3793  */
3794  if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {
3795  tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif);
3799  tif->tif_flags &= ~TIFF_ISTILED;
3800  } else {
3801  tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif);
3802  tif->tif_flags |= TIFF_ISTILED;
3803  }
3804  if (!tif->tif_dir.td_nstrips) {
3806  "Cannot handle zero number of %s",
3807  isTiled(tif) ? "tiles" : "strips");
3808  goto bad;
3809  }
3813  if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) {
3814 #ifdef OJPEG_SUPPORT
3816  (isTiled(tif)==0) &&
3817  (tif->tif_dir.td_nstrips==1)) {
3818  /*
3819  * XXX: OJPEG hack.
3820  * If a) compression is OJPEG, b) it's not a tiled TIFF,
3821  * and c) the number of strips is 1,
3822  * then we tolerate the absence of stripoffsets tag,
3823  * because, presumably, all required data is in the
3824  * JpegInterchangeFormat stream.
3825  */
3827  } else
3828 #endif
3829  {
3830  MissingRequired(tif,
3831  isTiled(tif) ? "TileOffsets" : "StripOffsets");
3832  goto bad;
3833  }
3834  }
3835  /*
3836  * Second pass: extract other information.
3837  */
3838  for (di=0, dp=dir; di<dircount; di++, dp++)
3839  {
3840  if (!dp->tdir_ignore) {
3841  switch (dp->tdir_tag)
3842  {
3845  case TIFFTAG_BITSPERSAMPLE:
3846  case TIFFTAG_DATATYPE:
3847  case TIFFTAG_SAMPLEFORMAT:
3848  /*
3849  * The MinSampleValue, MaxSampleValue, BitsPerSample
3850  * DataType and SampleFormat tags are supposed to be
3851  * written as one value/sample, but some vendors
3852  * incorrectly write one value only -- so we accept
3853  * that as well (yuck). Other vendors write correct
3854  * value for NumberOfSamples, but incorrect one for
3855  * BitsPerSample and friends, and we will read this
3856  * too.
3857  */
3858  {
3859  uint16 value;
3860  enum TIFFReadDirEntryErr err;
3861  err=TIFFReadDirEntryShort(tif,dp,&value);
3865  {
3866  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3867  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
3868  goto bad;
3869  }
3870  if (!TIFFSetField(tif,dp->tdir_tag,value))
3871  goto bad;
3872  if( dp->tdir_tag == TIFFTAG_BITSPERSAMPLE )
3873  bitspersample_read = TRUE;
3874  }
3875  break;
3878  {
3879 
3880  double *data = NULL;
3881  enum TIFFReadDirEntryErr err;
3882  uint32 saved_flags;
3883  int m;
3884  if (dp->tdir_count != (uint64)tif->tif_dir.td_samplesperpixel)
3886  else
3887  err = TIFFReadDirEntryDoubleArray(tif, dp, &data);
3889  {
3890  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3891  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
3892  goto bad;
3893  }
3894  saved_flags = tif->tif_flags;
3895  tif->tif_flags |= TIFF_PERSAMPLE;
3896  m = TIFFSetField(tif,dp->tdir_tag,data);
3897  tif->tif_flags = saved_flags;
3898  _TIFFfree(data);
3899  if (!m)
3900  goto bad;
3901  }
3902  break;
3903  case TIFFTAG_STRIPOFFSETS:
3904  case TIFFTAG_TILEOFFSETS:
3906  dp, sizeof(TIFFDirEntry) );
3907  break;
3911  dp, sizeof(TIFFDirEntry) );
3912  break;
3913  case TIFFTAG_COLORMAP:
3915  {
3916  enum TIFFReadDirEntryErr err;
3917  uint32 countpersample;
3918  uint32 countrequired;
3919  uint32 incrementpersample;
3920  uint16* value=NULL;
3921  /* It would be dangerous to instantiate those tag values */
3922  /* since if td_bitspersample has not yet been read (due to */
3923  /* unordered tags), it could be read afterwards with a */
3924  /* values greater than the default one (1), which may cause */
3925  /* crashes in user code */
3926  if( !bitspersample_read )
3927  {
3928  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3930  "Ignoring %s since BitsPerSample tag not found",
3931  fip ? fip->field_name : "unknown tagname");
3932  continue;
3933  }
3934  /* ColorMap or TransferFunction for high bit */
3935  /* depths do not make much sense and could be */
3936  /* used as a denial of service vector */
3937  if (tif->tif_dir.td_bitspersample > 24)
3938  {
3939  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3941  "Ignoring %s because BitsPerSample=%d>24",
3942  fip ? fip->field_name : "unknown tagname",
3943  tif->tif_dir.td_bitspersample);
3944  continue;
3945  }
3946  countpersample=(1U<<tif->tif_dir.td_bitspersample);
3947  if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample))
3948  {
3949  countrequired=countpersample;
3950  incrementpersample=0;
3951  }
3952  else
3953  {
3954  countrequired=3*countpersample;
3955  incrementpersample=countpersample;
3956  }
3957  if (dp->tdir_count!=(uint64)countrequired)
3959  else
3962  {
3963  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3964  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",1);
3965  }
3966  else
3967  {
3968  TIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample);
3969  _TIFFfree(value);
3970  }
3971  }
3972  break;
3973 /* BEGIN REV 4.0 COMPATIBILITY */
3974  case TIFFTAG_OSUBFILETYPE:
3975  {
3976  uint16 valueo;
3977  uint32 value;
3978  if (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk)
3979  {
3980  switch (valueo)
3981  {
3983  case OFILETYPE_PAGE: value=FILETYPE_PAGE; break;
3984  default: value=0; break;
3985  }
3986  if (value!=0)
3988  }
3989  }
3990  break;
3991 /* END REV 4.0 COMPATIBILITY */
3992  default:
3993  (void) TIFFFetchNormalTag(tif, dp, TRUE);
3994  break;
3995  }
3996  } /* -- if (!dp->tdir_ignore) */
3997  } /* -- for-loop -- */
3998 
3999  if( tif->tif_mode == O_RDWR &&
4008  {
4009  /* Directory typically created with TIFFDeferStrileArrayWriting() */
4010  TIFFSetupStrips(tif);
4011  }
4012  else if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) )
4013  {
4014  if( tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 )
4015  {
4017  tif->tif_dir.td_nstrips,
4018  &tif->tif_dir.td_stripoffset_p))
4019  {
4020  goto bad;
4021  }
4022  }
4023  if( tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 )
4024  {
4026  tif->tif_dir.td_nstrips,
4028  {
4029  goto bad;
4030  }
4031  }
4032  }
4033 
4034  /*
4035  * OJPEG hack:
4036  * - If a) compression is OJPEG, and b) photometric tag is missing,
4037  * then we consistently find that photometric should be YCbCr
4038  * - If a) compression is OJPEG, and b) photometric tag says it's RGB,
4039  * then we consistently find that the buggy implementation of the
4040  * buggy compression scheme matches photometric YCbCr instead.
4041  * - If a) compression is OJPEG, and b) bitspersample tag is missing,
4042  * then we consistently find bitspersample should be 8.
4043  * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
4044  * and c) photometric is RGB or YCbCr, then we consistently find
4045  * samplesperpixel should be 3
4046  * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
4047  * and c) photometric is MINISWHITE or MINISBLACK, then we consistently
4048  * find samplesperpixel should be 3
4049  */
4051  {
4052  if (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC))
4053  {
4055  "Photometric tag is missing, assuming data is YCbCr");
4057  goto bad;
4058  }
4059  else if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)
4060  {
4063  "Photometric tag value assumed incorrect, "
4064  "assuming data is YCbCr instead of RGB");
4065  }
4067  {
4069  "BitsPerSample tag is missing, assuming 8 bits per sample");
4070  if (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8))
4071  goto bad;
4072  }
4074  {
4076  {
4078  "SamplesPerPixel tag is missing, "
4079  "assuming correct SamplesPerPixel value is 3");
4081  goto bad;
4082  }
4084  {
4086  "SamplesPerPixel tag is missing, "
4087  "applying correct SamplesPerPixel value of 3");
4089  goto bad;
4090  }
4093  {
4094  /*
4095  * SamplesPerPixel tag is missing, but is not required
4096  * by spec. Assume correct SamplesPerPixel value of 1.
4097  */
4099  goto bad;
4100  }
4101  }
4102  }
4103 
4104  /*
4105  * Make sure all non-color channels are extrasamples.
4106  * If it's not the case, define them as such.
4107  */
4108  color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
4109  if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {
4110  uint16 old_extrasamples;
4111  uint16 *new_sampleinfo;
4112 
4113  TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "
4114  "color channels and ExtraSamples doesn't match SamplesPerPixel. "
4115  "Defining non-color channels as ExtraSamples.");
4116 
4117  old_extrasamples = tif->tif_dir.td_extrasamples;
4118  tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);
4119 
4120  // sampleinfo should contain information relative to these new extra samples
4121  new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
4122  if (!new_sampleinfo) {
4123  TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "
4124  "temporary new sampleinfo array (%d 16 bit elements)",
4125  tif->tif_dir.td_extrasamples);
4126  goto bad;
4127  }
4128 
4129  memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
4130  _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
4131  _TIFFfree(new_sampleinfo);
4132  }
4133 
4134  /*
4135  * Verify Palette image has a Colormap.
4136  */
4138  !TIFFFieldSet(tif, FIELD_COLORMAP)) {
4139  if ( tif->tif_dir.td_bitspersample>=8 && tif->tif_dir.td_samplesperpixel==3)
4141  else if (tif->tif_dir.td_bitspersample>=8)
4143  else {
4144  MissingRequired(tif, "Colormap");
4145  goto bad;
4146  }
4147  }
4148  /*
4149  * OJPEG hack:
4150  * We do no further messing with strip/tile offsets/bytecounts in OJPEG
4151  * TIFFs
4152  */
4154  {
4155  /*
4156  * Attempt to deal with a missing StripByteCounts tag.
4157  */
4158  if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) {
4159  /*
4160  * Some manufacturers violate the spec by not giving
4161  * the size of the strips. In this case, assume there
4162  * is one uncompressed strip of data.
4163  */
4165  tif->tif_dir.td_nstrips > 1) ||
4168  MissingRequired(tif, "StripByteCounts");
4169  goto bad;
4170  }
4172  "TIFF directory is missing required "
4173  "\"StripByteCounts\" field, calculating from imagelength");
4174  if (EstimateStripByteCounts(tif, dir, dircount) < 0)
4175  goto bad;
4176 
4177  } else if (tif->tif_dir.td_nstrips == 1
4178  && !(tif->tif_flags&TIFF_ISTILED)
4179  && ByteCountLooksBad(tif)) {
4180  /*
4181  * XXX: Plexus (and others) sometimes give a value of
4182  * zero for a tag when they don't know what the
4183  * correct value is! Try and handle the simple case
4184  * of estimating the size of a one strip image.
4185  */
4187  "Bogus \"StripByteCounts\" field, ignoring and calculating from imagelength");
4188  if(EstimateStripByteCounts(tif, dir, dircount) < 0)
4189  goto bad;
4190 
4191  } else if (!(tif->tif_flags&TIFF_DEFERSTRILELOAD)
4193  && tif->tif_dir.td_nstrips > 2
4195  && TIFFGetStrileByteCount(tif, 0) != TIFFGetStrileByteCount(tif, 1)
4196  && TIFFGetStrileByteCount(tif, 0) != 0
4197  && TIFFGetStrileByteCount(tif, 1) != 0 ) {
4198  /*
4199  * XXX: Some vendors fill StripByteCount array with
4200  * absolutely wrong values (it can be equal to
4201  * StripOffset array, for example). Catch this case
4202  * here.
4203  *
4204  * We avoid this check if deferring strile loading
4205  * as it would always force us to load the strip/tile
4206  * information.
4207  */
4209  "Wrong \"StripByteCounts\" field, ignoring and calculating from imagelength");
4210  if (EstimateStripByteCounts(tif, dir, dircount) < 0)
4211  goto bad;
4212  }
4213  }
4214  if (dir)
4215  {
4216  _TIFFfree(dir);
4217  dir=NULL;
4218  }
4220  {
4221  if (tif->tif_dir.td_bitspersample>=16)
4222  tif->tif_dir.td_maxsamplevalue=0xFFFF;
4223  else
4225  }
4226 
4227 #ifdef STRIPBYTECOUNTSORTED_UNUSED
4228  /*
4229  * XXX: We can optimize checking for the strip bounds using the sorted
4230  * bytecounts array. See also comments for TIFFAppendToStrip()
4231  * function in tif_write.c.
4232  */
4233  if (!(tif->tif_flags&TIFF_DEFERSTRILELOAD) && tif->tif_dir.td_nstrips > 1) {
4234  uint32 strip;
4235 
4236  tif->tif_dir.td_stripbytecountsorted = 1;
4237  for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {
4238  if (TIFFGetStrileOffset(tif, strip - 1) >
4239  TIFFGetStrileOffset(tif, strip)) {
4240  tif->tif_dir.td_stripbytecountsorted = 0;
4241  break;
4242  }
4243  }
4244  }
4245 #endif
4246 
4247  /*
4248  * An opportunity for compression mode dependent tag fixup
4249  */
4250  (*tif->tif_fixuptags)(tif);
4251 
4252  /*
4253  * Some manufacturers make life difficult by writing
4254  * large amounts of uncompressed data as a single strip.
4255  * This is contrary to the recommendations of the spec.
4256  * The following makes an attempt at breaking such images
4257  * into strips closer to the recommended 8k bytes. A
4258  * side effect, however, is that the RowsPerStrip tag
4259  * value may be changed.
4260  */
4262  (tif->tif_dir.td_nstrips==1)&&
4265  {
4267  }
4268 
4269  /* There are also uncompressed striped files with strips larger than */
4270  /* 2 GB, which make them unfriendly with a lot of code. If possible, */
4271  /* try to expose smaller "virtual" strips. */
4275  TIFFStripSize64(tif) > 0x7FFFFFFFUL )
4276  {
4278  }
4279 
4280  /*
4281  * Clear the dirty directory flag.
4282  */
4283  tif->tif_flags &= ~TIFF_DIRTYDIRECT;
4284  tif->tif_flags &= ~TIFF_DIRTYSTRIP;
4285 
4286  /*
4287  * Reinitialize i/o since we are starting on a new directory.
4288  */
4289  tif->tif_row = (uint32) -1;
4290  tif->tif_curstrip = (uint32) -1;
4291  tif->tif_col = (uint32) -1;
4292  tif->tif_curtile = (uint32) -1;
4293  tif->tif_tilesize = (tmsize_t) -1;
4294 
4295  tif->tif_scanlinesize = TIFFScanlineSize(tif);
4296  if (!tif->tif_scanlinesize) {
4298  "Cannot handle zero scanline size");
4299  return (0);
4300  }
4301 
4302  if (isTiled(tif)) {
4303  tif->tif_tilesize = TIFFTileSize(tif);
4304  if (!tif->tif_tilesize) {
4306  "Cannot handle zero tile size");
4307  return (0);
4308  }
4309  } else {
4310  if (!TIFFStripSize(tif)) {
4312  "Cannot handle zero strip size");
4313  return (0);
4314  }
4315  }
4316  return (1);
4317 bad:
4318  if (dir)
4319  _TIFFfree(dir);
4320  return (0);
4321 }
unsigned long long uint64
Definition: platform.h:18
#define TIFFTAG_SUBFILETYPE
Definition: tiff.h:146
#define TIFF_BEENWRITING
Definition: tiffiop.h:125
#define FIELD_IGNORE
Definition: tif_dir.h:138
uint8 tdir_ignore
Definition: tif_dir.h:61
uint16 td_bitspersample
Definition: tif_dir.h:75
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:202
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4358
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define TIFF_UINT64_FORMAT
Definition: tif_config.h:52
uint32 td_tiledepth
Definition: tif_dir.h:73
#define TIFFTAG_BITSPERSAMPLE
Definition: tiff.h:156
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:233
TIFFField * _TIFFCreateAnonField(TIFF *tif, uint32 tag, TIFFDataType field_type)
Definition: tif_dirinfo.c:634
TIFFReadDirEntryErr
Definition: tif_dirread.c:56
uint32 TIFFNumberOfStrips(TIFF *tif)
Definition: tif_strip.c:59
int TIFFSetupStrips(TIFF *tif)
Definition: tif_write.c:523
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
Definition: tif_dirread.c:2530
static int _TIFFGetMaxColorChannels(uint16 photometric)
Definition: tif_dirread.c:3502
#define FIELD_STRIPOFFSETS
Definition: tif_dir.h:162
#define TIFFTAG_STRIPBYTECOUNTS
Definition: tiff.h:234
#define TIFFTAG_COLORMAP
Definition: tiff.h:284
#define TRUE
Definition: types.h:120
#define TIFF_STRIPCHOP
Definition: tiffiop.h:134
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:304
#define FIELD_IMAGEDIMENSIONS
Definition: tif_dir.h:141
unsigned int uint32
Definition: types.h:32
#define TIFF_ISTILED
Definition: tiffiop.h:129
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:154
#define U(x)
Definition: wordpad.c:45
#define TIFFTAG_DATATYPE
Definition: tiff.h:385
#define TIFFTAG_MINSAMPLEVALUE
Definition: tiff.h:235
uint64 toff_t
Definition: tiffio.h:66
uint32 tif_curstrip
Definition: tiffiop.h:161
uint64 * td_stripbytecount_p
Definition: tif_dir.h:102
static int TIFFFetchNormalTag(TIFF *, TIFFDirEntry *, int recover)
Definition: tif_dirread.c:4964
#define assert(x)
Definition: debug.h:53
uint32 td_imagedepth
Definition: tif_dir.h:72
#define TIFFTAG_STRIPOFFSETS
Definition: tiff.h:222
tmsize_t tif_scanlinesize
Definition: tiffiop.h:193
#define OFILETYPE_PAGE
Definition: tiff.h:153
#define COMPRESSION_OJPEG
Definition: tiff.h:165
thandle_t tif_clientdata
Definition: tiffiop.h:207
#define TIFFTAG_SMINSAMPLEVALUE
Definition: tiff.h:315
uint32 TIFFNumberOfTiles(TIFF *tif)
Definition: tif_tile.c:113
uint16 tif_curdir
Definition: tiffiop.h:160
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:239
tmsize_t tif_tilesize
Definition: tiffiop.h:170
#define TIFF_DIRTYDIRECT
Definition: tiffiop.h:122
const GLfloat * m
Definition: glext.h:10848
#define TIFFTAG_TILEBYTECOUNTS
Definition: tiff.h:289
uint32 td_tilelength
Definition: tif_dir.h:73
unsigned short field_bit
Definition: tif_dir.h:290
tmsize_t TIFFStripSize(TIFF *tif)
Definition: tif_strip.c:202
#define PHOTOMETRIC_RGB
Definition: tiff.h:198
#define FIELD_MAXSAMPLEVALUE
Definition: tif_dir.h:157
#define FIELD_BITSPERSAMPLE
Definition: tif_dir.h:148
static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
Definition: tif_dirread.c:4324
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:197
#define FALSE
Definition: types.h:117
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:286
char * field_name
Definition: tif_dir.h:293
#define FIELD_STRIPBYTECOUNTS
Definition: tif_dir.h:161
uint16 * td_sampleinfo
Definition: tif_dir.h:95
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32 nstrips, uint64 **lpp)
Definition: tif_dirread.c:5649
TIFFDirEntry td_stripbytecount_entry
Definition: tif_dir.h:108
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32 n)
Definition: tif_dirinfo.c:369
uint32 td_stripsperimage
Definition: tif_dir.h:99
#define TIFFTAG_TILELENGTH
Definition: tiff.h:287
int tif_mode
Definition: tiffiop.h:118
#define FAILED_FII
Definition: tif_dirread.c:41
uint32 tif_flags
Definition: tiffiop.h:119
#define PHOTOMETRIC_MINISWHITE
Definition: tiff.h:196
smooth NULL
Definition: ftsmooth.c:416
#define TIFFTAG_IMAGELENGTH
Definition: tiff.h:155
#define TIFFTAG_TILEOFFSETS
Definition: tiff.h:288
#define TIFFTAG_SAMPLESPERPIXEL
Definition: tiff.h:232
uint16 td_planarconfig
Definition: tif_dir.h:89
static void TryChopUpUncompressedBigTiff(TIFF *)
Definition: tif_dirread.c:5898
unsigned int dir
Definition: maze.c:112
uint64 TIFFGetStrileOffset(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6290
uint64 tif_nextdiroff
Definition: tiffiop.h:147
#define PHOTOMETRIC_PALETTE
Definition: tiff.h:199
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1268
#define TIFF_BUF4WRITE
Definition: tiffiop.h:139
static void MissingRequired(TIFF *, const char *)
Definition: tif_dirread.c:4616
#define PHOTOMETRIC_MINISBLACK
Definition: tiff.h:197
uint32 td_nstrips
Definition: tif_dir.h:100
#define TIFF_PERSAMPLE
Definition: tiffiop.h:141
uint16 td_extrasamples
Definition: tif_dir.h:94
uint16 td_photometric
Definition: tif_dir.h:78
int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
Definition: tif_dirinfo.c:958
uint16 tdir_tag
Definition: tif_dir.h:53
static int EstimateStripByteCounts(TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
Definition: tif_dirread.c:4509
#define FIELD_PHOTOMETRIC
Definition: tif_dir.h:150
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define TIFFTAG_PHOTOMETRIC
Definition: tiff.h:195
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:196
void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
Definition: tif_unix.c:317
uint64 tdir_count
Definition: tif_dir.h:55
#define TIFF_DIRTYSTRIP
Definition: tiffiop.h:140
static const WCHAR L[]
Definition: oid.c:1250
#define TIFFTAG_TRANSFERFUNCTION
Definition: tiff.h:273
uint64 tif_diroff
Definition: tiffiop.h:146
uint32 tif_curtile
Definition: tiffiop.h:169
#define COMPRESSION_NONE
Definition: tiff.h:158
#define TIFFTAG_COMPRESSION
Definition: tiff.h:157
uint32 td_tilewidth
Definition: tif_dir.h:73
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:241
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
union TIFFDirEntry::@3425 tdir_offset
#define FILETYPE_REDUCEDIMAGE
Definition: tiff.h:147
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:188
#define TIFF_DEFERSTRILELOAD
Definition: tiffiop.h:143
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558
#define err(...)
#define isTiled(tif)
Definition: tiffiop.h:229
#define TIFFTAG_SMAXSAMPLEVALUE
Definition: tiff.h:316
GLsizei const GLfloat * value
Definition: glext.h:6069
#define FILETYPE_PAGE
Definition: tiff.h:148
static void ChopUpSingleUncompressedStrip(TIFF *)
Definition: tif_dirread.c:5828
TIFFField ** tif_fields
Definition: tiffiop.h:216
uint16 td_maxsamplevalue
Definition: tif_dir.h:84
#define OFILETYPE_REDUCEDIMAGE
Definition: tiff.h:152
uint32 td_rowsperstrip
Definition: tif_dir.h:83
uint32 tif_row
Definition: tiffiop.h:159
#define TIFFTAG_TILEDEPTH
Definition: tiff.h:387
uint64 TIFFStripSize64(TIFF *tif)
Definition: tif_strip.c:193
#define TIFFTAG_IMAGEDEPTH
Definition: tiff.h:386
tmsize_t TIFFScanlineSize(TIFF *tif)
Definition: tif_strip.c:314
unsigned short uint16
Definition: types.h:30
#define O_RDWR
Definition: fcntl.h:36
TIFFBoolMethod tif_fixuptags
Definition: tiffiop.h:173
TIFFDirectory tif_dir
Definition: tiffiop.h:151
TIFFDirEntry td_stripoffset_entry
Definition: tif_dir.h:107
#define FIELD_TILEDIMENSIONS
Definition: tif_dir.h:142
static int TIFFCheckDirOffset(TIFF *tif, uint64 diroff)
Definition: tif_dirread.c:4632
uint64 * td_stripoffset_p
Definition: tif_dir.h:101
tmsize_t TIFFTileSize(TIFF *tif)
Definition: tif_tile.c:257
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:292
static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:2828
int TIFFDefaultDirectory(TIFF *tif)
Definition: tif_dir.c:1372
void _TIFFsetShortArray(uint16 **wpp, uint16 *wp, uint32 n)
Definition: tif_dir.c:63
#define FIELD_COLORMAP
Definition: tif_dir.h:163
#define FIELD_SAMPLESPERPIXEL
Definition: tif_dir.h:154
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3410
uint16 td_samplesperpixel
Definition: tif_dir.h:82
#define TIFF_CHOPPEDUPARRAYS
Definition: tiffiop.h:145
static int ByteCountLooksBad(TIFF *tif)
Definition: tif_dirread.c:3526
static TIFFDirEntry * TIFFReadDirectoryFindEntry(TIFF *tif, TIFFDirEntry *dir, uint16 dircount, uint16 tagid)
Definition: tif_dirread.c:4344
uint16 td_compression
Definition: tif_dir.h:77
void _TIFFfree(void *p)
Definition: tif_unix.c:326
uint32 tif_col
Definition: tiffiop.h:168
#define TIFFTAG_SAMPLEFORMAT
Definition: tiff.h:308
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF *tif, TIFFDirEntry *direntry, uint16 **value)
Definition: tif_dirread.c:1294
#define TIFFTAG_OSUBFILETYPE
Definition: tiff.h:150
static uint16 TIFFFetchDirectory(TIFF *tif, uint64 diroff, TIFFDirEntry **pdir, uint64 *nextdiroff)
Definition: tif_dirread.c:4706
uint32 td_imagewidth
Definition: tif_dir.h:72
uint64 toff_long8
Definition: tif_dir.h:59
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:807
uint64 TIFFGetStrileByteCount(TIFF *tif, uint32 strile)
Definition: tif_dirread.c:6305
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Definition: tif_unix.c:344
#define TIFFTAG_MAXSAMPLEVALUE
Definition: tiff.h:236
TIFFDataType
Definition: tiff.h:123
#define PLANARCONFIG_CONTIG
Definition: tiff.h:240
int _TIFFFillStriles(TIFF *tif)
Definition: tif_dirread.c:6320
uint16 tdir_type
Definition: tif_dir.h:54

Referenced by TIFFClientOpen(), TIFFSetDirectory(), and TIFFSetSubDirectory().

◆ TIFFReadDirectoryCheckOrder()

static void TIFFReadDirectoryCheckOrder ( TIFF tif,
TIFFDirEntry dir,
uint16  dircount 
)
static

Definition at line 4324 of file tif_dirread.c.

4325 {
4326  static const char module[] = "TIFFReadDirectoryCheckOrder";
4327  uint16 m;
4328  uint16 n;
4329  TIFFDirEntry* o;
4330  m=0;
4331  for (n=0, o=dir; n<dircount; n++, o++)
4332  {
4333  if (o->tdir_tag<m)
4334  {
4336  "Invalid TIFF directory; tags are not sorted in ascending order");
4337  break;
4338  }
4339  m=o->tdir_tag+1;
4340  }
4341 }
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
GLdouble n
Definition: glext.h:7729
thandle_t tif_clientdata
Definition: tiffiop.h:207
const GLfloat * m
Definition: glext.h:10848
unsigned int dir
Definition: maze.c:112
uint16 tdir_tag
Definition: tif_dir.h:53
unsigned short uint16
Definition: types.h:30

Referenced by TIFFReadCustomDirectory(), and TIFFReadDirectory().

◆ TIFFReadDirectoryFindEntry()

static TIFFDirEntry * TIFFReadDirectoryFindEntry ( TIFF tif,
TIFFDirEntry dir,
uint16  dircount,
uint16  tagid 
)
static

Definition at line 4344 of file tif_dirread.c.

4345 {
4346  TIFFDirEntry* m;
4347  uint16 n;
4348  (void) tif;
4349  for (m=dir, n=0; n<dircount; m++, n++)
4350  {
4351  if (m->tdir_tag==tagid)
4352  return(m);
4353  }
4354  return(0);
4355 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
GLdouble n
Definition: glext.h:7729
const GLfloat * m
Definition: glext.h:10848
unsigned int dir
Definition: maze.c:112
unsigned short uint16
Definition: types.h:30

Referenced by TIFFReadDirectory().

◆ TIFFReadDirectoryFindFieldInfo()

static void TIFFReadDirectoryFindFieldInfo ( TIFF tif,
uint16  tagid,
uint32 fii 
)
static

Definition at line 4358 of file tif_dirread.c.

4359 {
4360  int32 ma,mb,mc;
4361  ma=-1;
4362  mc=(int32)tif->tif_nfields;
4363  while (1)
4364  {
4365  if (ma+1==mc)
4366  {
4367  *fii = FAILED_FII;
4368  return;
4369  }
4370  mb=(ma+mc)/2;
4371  if (tif->tif_fields[mb]->field_tag==(uint32)tagid)
4372  break;
4373  if (tif->tif_fields[mb]->field_tag<(uint32)tagid)
4374  ma=mb;
4375  else
4376  mc=mb;
4377  }
4378  while (1)
4379  {
4380  if (mb==0)
4381  break;
4382  if (tif->tif_fields[mb-1]->field_tag!=(uint32)tagid)
4383  break;
4384  mb--;
4385  }
4386  *fii=mb;
4387 }
unsigned int uint32
Definition: types.h:32
while(1)
Definition: macro.lex.yy.c:740
#define FAILED_FII
Definition: tif_dirread.c:41
size_t tif_nfields
Definition: tiffiop.h:217
uint32 field_tag
Definition: tif_dir.h:283
TIFFField ** tif_fields
Definition: tiffiop.h:216
long int32
Definition: platform.h:12

Referenced by TIFFFetchNormalTag(), TIFFReadCustomDirectory(), and TIFFReadDirectory().

◆ TIFFReadDirEntryArray()

static enum TIFFReadDirEntryErr TIFFReadDirEntryArray (