ReactOS  0.4.14-dev-323-g6fe6a88
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 IGNORE   0 /* tag placeholder used below */
 
#define FAILED_FII   ((uint32) -1)
 
#define INITIAL_THRESHOLD   (1024 * 1024)
 
#define THRESHOLD_MULTIPLIER   10
 
#define MAX_THRESHOLD   (THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * THRESHOLD_MULTIPLIER * INITIAL_THRESHOLD)
 
#define TIFF_UINT32_MAX   0xFFFFFFFFU
 
#define TIFF_INT64_MAX   ((int64)(((uint64) ~0) >> 1))
 
#define BYTECOUNTLOOKSBAD
 

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 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)
 
int TIFFReadDirectory (TIFF *tif)
 
int TIFFReadCustomDirectory (TIFF *tif, toff_t diroff, const TIFFFieldArray *infoarray)
 
int TIFFReadEXIFDirectory (TIFF *tif, toff_t diroff)
 
int _TIFFFillStriles (TIFF *tif)
 

Macro Definition Documentation

◆ BYTECOUNTLOOKSBAD

#define BYTECOUNTLOOKSBAD
Value:
( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \
(tif->tif_dir.td_compression == COMPRESSION_NONE && \
(tif->tif_dir.td_stripoffset[0] <= TIFFGetFileSize(tif) && \
tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0])) || \
(tif->tif_mode == O_RDONLY && \
tif->tif_dir.td_compression == COMPRESSION_NONE && \
tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) )
uint64 TIFFScanlineSize64(TIFF *tif)
Definition: tif_strip.c:273
#define COMPRESSION_NONE
Definition: tiff.h:158
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:225
#define O_RDONLY
Definition: acwin.h:108

◆ FAILED_FII

#define FAILED_FII   ((uint32) -1)

Definition at line 45 of file tif_dirread.c.

◆ IGNORE

#define IGNORE   0 /* tag placeholder used below */

Definition at line 44 of file tif_dirread.c.

◆ INITIAL_THRESHOLD

#define INITIAL_THRESHOLD   (1024 * 1024)

Definition at line 771 of file tif_dirread.c.

◆ MAX_THRESHOLD

◆ THRESHOLD_MULTIPLIER

#define THRESHOLD_MULTIPLIER   10

Definition at line 772 of file tif_dirread.c.

◆ TIFF_INT64_MAX

#define TIFF_INT64_MAX   ((int64)(((uint64) ~0) >> 1))

Definition at line 3383 of file tif_dirread.c.

◆ TIFF_UINT32_MAX

#define TIFF_UINT32_MAX   0xFFFFFFFFU

Definition at line 3293 of file tif_dirread.c.

Typedef Documentation

◆ UInt64Aligned_t

Enumeration Type Documentation

◆ TIFFReadDirEntryErr

Enumerator
TIFFReadDirEntryErrOk 
TIFFReadDirEntryErrCount 
TIFFReadDirEntryErrType 
TIFFReadDirEntryErrIo 
TIFFReadDirEntryErrRange 
TIFFReadDirEntryErrPsdif 
TIFFReadDirEntryErrSizesan 
TIFFReadDirEntryErrAlloc 

Definition at line 55 of file tif_dirread.c.

Function Documentation

◆ _TIFFFillStriles()

int _TIFFFillStriles ( TIFF tif)

◆ _TIFFFillStrilesInternal()

static int _TIFFFillStrilesInternal ( TIFF tif,
int  loadStripByteCount 
)
static

Definition at line 5817 of file tif_dirread.c.

5818 {
5819 #if defined(DEFER_STRILE_LOAD)
5820  register TIFFDirectory *td = &tif->tif_dir;
5821  int return_value = 1;
5822 
5823  if( td->td_stripoffset != NULL )
5824  return 1;
5825 
5826  if( td->td_stripoffset_entry.tdir_count == 0 )
5827  return 0;
5828 
5829  if (!TIFFFetchStripThing(tif,&(td->td_stripoffset_entry),
5830  td->td_nstrips,&td->td_stripoffset))
5831  {
5832  return_value = 0;
5833  }
5834 
5835  if (loadStripByteCount &&
5836  !TIFFFetchStripThing(tif,&(td->td_stripbytecount_entry),
5837  td->td_nstrips,&td->td_stripbytecount))
5838  {
5839  return_value = 0;
5840  }
5841 
5842  _TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
5843  _TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
5844 
5845  if (tif->tif_dir.td_nstrips > 1 && return_value == 1 ) {
5846  uint32 strip;
5847 
5849  for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {
5850  if (tif->tif_dir.td_stripoffset[strip - 1] >
5851  tif->tif_dir.td_stripoffset[strip]) {
5853  break;
5854  }
5855  }
5856  }
5857 
5858  return return_value;
5859 #else /* !defined(DEFER_STRILE_LOAD) */
5860  (void) tif;
5861  (void) loadStripByteCount;
5862  return 1;
5863 #endif
5864 }
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned int uint32
Definition: types.h:32
int td_stripbytecountsorted
Definition: tif_dir.h:102
static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32 nstrips, uint64 **lpp)
Definition: tif_dirread.c:5599
smooth NULL
Definition: ftsmooth.c:416
uint32 td_nstrips
Definition: tif_dir.h:99
uint64 * td_stripoffset
Definition: tif_dir.h:100
uint64 * td_stripbytecount
Definition: tif_dir.h:101
TIFFDirectory tif_dir
Definition: tiffiop.h:135

Referenced by _TIFFFillStriles(), and EstimateStripByteCounts().

◆ _TIFFGetMaxColorChannels()

static int _TIFFGetMaxColorChannels ( uint16  photometric)
static

Definition at line 3513 of file tif_dirread.c.

3514 {
3515  switch (photometric) {
3516  case PHOTOMETRIC_PALETTE:
3519  return 1;
3520  case PHOTOMETRIC_YCBCR:
3521  case PHOTOMETRIC_RGB:
3522  case PHOTOMETRIC_CIELAB:
3523  case PHOTOMETRIC_LOGLUV:
3524  case PHOTOMETRIC_ITULAB:
3525  case PHOTOMETRIC_ICCLAB:
3526  return 3;
3527  case PHOTOMETRIC_SEPARATED:
3528  case PHOTOMETRIC_MASK:
3529  return 4;
3530  case PHOTOMETRIC_LOGL:
3531  case PHOTOMETRIC_CFA:
3532  default:
3533  return 0;
3534  }
3535 }
#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().

◆ CheckDirCount()

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

Definition at line 4632 of file tif_dirread.c.

4633 {
4634  if ((uint64)count > dir->tdir_count) {
4635  const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag);
4637  "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag ignored",
4638  fip ? fip->field_name : "unknown tagname",
4639  dir->tdir_count, count);
4640  return (0);
4641  } else if ((uint64)count < dir->tdir_count) {
4642  const TIFFField* fip = TIFFFieldWithTag(tif, dir->tdir_tag);
4644  "incorrect count for field \"%s\" (" TIFF_UINT64_FORMAT ", expecting %u); tag trimmed",
4645  fip ? fip->field_name : "unknown tagname",
4646  dir->tdir_count, count);
4647  dir->tdir_count = count;
4648  return (1);
4649  }
4650  return (1);
4651 }
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:191
char * tif_name
Definition: tiffiop.h:103
char * field_name
Definition: tif_dir.h:289
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 5709 of file tif_dirread.c.

5710 {
5711  register TIFFDirectory *td = &tif->tif_dir;
5712  uint64 bytecount;
5713  uint64 offset;
5714  uint32 rowblock;
5715  uint64 rowblockbytes;
5716  uint64 stripbytes;
5717  uint32 strip;
5718  uint32 nstrips;
5719  uint32 rowsperstrip;
5720  uint64* newcounts;
5721  uint64* newoffsets;
5722 
5723  bytecount = td->td_stripbytecount[0];
5724  /* On a newly created file, just re-opened to be filled, we */
5725  /* don't want strip chop to trigger as it is going to cause issues */
5726  /* later ( StripOffsets and StripByteCounts improperly filled) . */
5727  if( bytecount == 0 && tif->tif_mode != O_RDONLY )
5728  return;
5729  offset = td->td_stripoffset[0];
5731  if ((td->td_photometric == PHOTOMETRIC_YCBCR)&&
5732  (!isUpSampled(tif)))
5733  rowblock = td->td_ycbcrsubsampling[1];
5734  else
5735  rowblock = 1;
5736  rowblockbytes = TIFFVTileSize64(tif, rowblock);
5737  /*
5738  * Make the rows hold at least one scanline, but fill specified amount
5739  * of data if possible.
5740  */
5741  if (rowblockbytes > STRIP_SIZE_DEFAULT) {
5742  stripbytes = rowblockbytes;
5743  rowsperstrip = rowblock;
5744  } else if (rowblockbytes > 0 ) {
5745  uint32 rowblocksperstrip;
5746  rowblocksperstrip = (uint32) (STRIP_SIZE_DEFAULT / rowblockbytes);
5747  rowsperstrip = rowblocksperstrip * rowblock;
5748  stripbytes = rowblocksperstrip * rowblockbytes;
5749  }
5750  else
5751  return;
5752 
5753  /*
5754  * never increase the number of rows per strip
5755  */
5756  if (rowsperstrip >= td->td_rowsperstrip)
5757  return;
5758  nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip);
5759  if( nstrips == 0 )
5760  return;
5761 
5762  /* If we are going to allocate a lot of memory, make sure that the */
5763  /* file is as big as needed */
5764  if( tif->tif_mode == O_RDONLY &&
5765  nstrips > 1000000 &&
5766  (offset >= TIFFGetFileSize(tif) ||
5767  stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
5768  {
5769  return;
5770  }
5771 
5772  newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
5773  "for chopped \"StripByteCounts\" array");
5774  newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
5775  "for chopped \"StripOffsets\" array");
5776  if (newcounts == NULL || newoffsets == NULL) {
5777  /*
5778  * Unable to allocate new strip information, give up and use
5779  * the original one strip information.
5780  */
5781  if (newcounts != NULL)
5782  _TIFFfree(newcounts);
5783  if (newoffsets != NULL)
5784  _TIFFfree(newoffsets);
5785  return;
5786  }
5787  /*
5788  * Fill the strip information arrays with new bytecounts and offsets
5789  * that reflect the broken-up format.
5790  */
5791  for (strip = 0; strip < nstrips; strip++) {
5792  if (stripbytes > bytecount)
5793  stripbytes = bytecount;
5794  newcounts[strip] = stripbytes;
5795  newoffsets[strip] = stripbytes ? offset : 0;
5796  offset += stripbytes;
5797  bytecount -= stripbytes;
5798  }
5799  /*
5800  * Replace old single strip info with multi-strip info.
5801  */
5802  td->td_stripsperimage = td->td_nstrips = nstrips;
5803  TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
5804 
5807  td->td_stripbytecount = newcounts;
5808  td->td_stripoffset = newoffsets;
5809  td->td_stripbytecountsorted = 1;
5810 }
unsigned long long uint64
Definition: platform.h:18
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:202
#define TIFFTAG_ROWSPERSTRIP
Definition: tiff.h:233
#define TIFFhowmany_32(x, y)
Definition: tiffiop.h:248
#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:216
int td_stripbytecountsorted
Definition: tif_dir.h:102
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:85
uint32 td_stripsperimage
Definition: tif_dir.h:98
int tif_mode
Definition: tiffiop.h:105
smooth NULL
Definition: ftsmooth.c:416
uint16 td_planarconfig
Definition: tif_dir.h:88
uint32 td_nstrips
Definition: tif_dir.h:99
uint32 td_imagelength
Definition: tif_dir.h:71
uint16 td_photometric
Definition: tif_dir.h:77
uint64 * td_stripoffset
Definition: tif_dir.h:100
uint64 * td_stripbytecount
Definition: tif_dir.h:101
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:225
uint32 td_rowsperstrip
Definition: tif_dir.h:82
uint16 td_ycbcrsubsampling[2]
Definition: tif_dir.h:110
TIFFDirectory tif_dir
Definition: tiffiop.h:135
void _TIFFfree(void *p)
Definition: tif_unix.c:326
uint64 TIFFVTileSize64(TIFF *tif, uint32 nrows)
Definition: tif_tile.c:200
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:790
#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 4478 of file tif_dirread.c.

4479 {
4480  static const char module[] = "EstimateStripByteCounts";
4481 
4482  TIFFDirEntry *dp;
4483  TIFFDirectory *td = &tif->tif_dir;
4484  uint32 strip;
4485 
4486  /* Do not try to load stripbytecount as we will compute it */
4487  if( !_TIFFFillStrilesInternal( tif, 0 ) )
4488  return -1;
4489 
4490  if (td->td_stripbytecount)
4492  td->td_stripbytecount = (uint64*)
4494  "for \"StripByteCounts\" array");
4495  if( td->td_stripbytecount == NULL )
4496  return -1;
4497 
4498  if (td->td_compression != COMPRESSION_NONE) {
4499  uint64 space;
4500  uint64 filesize;
4501  uint16 n;
4502  filesize = TIFFGetFileSize(tif);
4503  if (!(tif->tif_flags&TIFF_BIGTIFF))
4504  space=sizeof(TIFFHeaderClassic)+2+dircount*12+4;
4505  else
4506  space=sizeof(TIFFHeaderBig)+8+dircount*20+8;
4507  /* calculate amount of space used by indirect values */
4508  for (dp = dir, n = dircount; n > 0; n--, dp++)
4509  {
4510  uint32 typewidth;
4511  uint64 datasize;
4512  typewidth = TIFFDataWidth((TIFFDataType) dp->tdir_type);
4513  if (typewidth == 0) {
4515  "Cannot determine size of unknown tag type %d",
4516  dp->tdir_type);
4517  return -1;
4518  }
4519  datasize=(uint64)typewidth*dp->tdir_count;
4520  if (!(tif->tif_flags&TIFF_BIGTIFF))
4521  {
4522  if (datasize<=4)
4523  datasize=0;
4524  }
4525  else
4526  {
4527  if (datasize<=8)
4528  datasize=0;
4529  }
4530  space+=datasize;
4531  }
4532  if( filesize < space )
4533  /* we should perhaps return in error ? */
4534  space = filesize;
4535  else
4536  space = filesize - space;
4538  space /= td->td_samplesperpixel;
4539  for (strip = 0; strip < td->td_nstrips; strip++)
4540  td->td_stripbytecount[strip] = space;
4541  /*
4542  * This gross hack handles the case were the offset to
4543  * the last strip is past the place where we think the strip
4544  * should begin. Since a strip of data must be contiguous,
4545  * it's safe to assume that we've overestimated the amount
4546  * of data in the strip and trim this number back accordingly.
4547  */
4548  strip--;
4549  if (td->td_stripoffset[strip]+td->td_stripbytecount[strip] > filesize)
4550  td->td_stripbytecount[strip] = filesize - td->td_stripoffset[strip];
4551  } else if (isTiled(tif)) {
4552  uint64 bytespertile = TIFFTileSize64(tif);
4553 
4554  for (strip = 0; strip < td->td_nstrips; strip++)
4555  td->td_stripbytecount[strip] = bytespertile;
4556  } else {
4557  uint64 rowbytes = TIFFScanlineSize64(tif);
4558  uint32 rowsperstrip = td->td_imagelength/td->td_stripsperimage;
4559  for (strip = 0; strip < td->td_nstrips; strip++)
4560  td->td_stripbytecount[strip] = rowbytes * rowsperstrip;
4561  }
4563  if (!TIFFFieldSet(tif, FIELD_ROWSPERSTRIP))
4564  td->td_rowsperstrip = td->td_imagelength;
4565  return 1;
4566 }
unsigned long long uint64
Definition: platform.h:18
static SIZE_T datasize
Definition: asm.c:30
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
unsigned int uint32
Definition: types.h:32
GLdouble n
Definition: glext.h:7729
thandle_t tif_clientdata
Definition: tiffiop.h:191
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:193
#define TIFF_BIGTIFF
Definition: tiffiop.h:125
#define FIELD_STRIPBYTECOUNTS
Definition: tif_dir.h:157
uint64 TIFFScanlineSize64(TIFF *tif)
Definition: tif_strip.c:273
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:85
uint32 td_stripsperimage
Definition: tif_dir.h:98
uint32 tif_flags
Definition: tiffiop.h:106
smooth NULL
Definition: ftsmooth.c:416
uint16 td_planarconfig
Definition: tif_dir.h:88
unsigned int dir
Definition: maze.c:112
uint32 td_nstrips
Definition: tif_dir.h:99
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint32 td_imagelength
Definition: tif_dir.h:71
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_error.c:65
#define TIFFFieldSet(tif, field)
Definition: tif_dir.h:192
uint64 TIFFTileSize64(TIFF *tif)
Definition: tif_tile.c:267
uint64 * td_stripoffset
Definition: tif_dir.h:100
#define FIELD_ROWSPERSTRIP
Definition: tif_dir.h:151
uint64 tdir_count
Definition: tif_dir.h:55
#define COMPRESSION_NONE
Definition: tiff.h:158
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:241
uint64 * td_stripbytecount
Definition: tif_dir.h:101
#define TIFFGetFileSize(tif)
Definition: tiffiop.h:225
#define isTiled(tif)
Definition: tiffiop.h:213
int TIFFDataWidth(TIFFDataType type)
Definition: tif_dirinfo.c:438
uint32 td_rowsperstrip
Definition: tif_dir.h:82
unsigned short uint16
Definition: types.h:30
TIFFDirectory tif_dir
Definition: tiffiop.h:135
static int _TIFFFillStrilesInternal(TIFF *tif, int loadStripByteCount)
Definition: tif_dirread.c:5817
uint16 td_samplesperpixel
Definition: tif_dir.h:81
uint16 td_compression
Definition: tif_dir.h:76
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 4569 of file tif_dirread.c.

4570 {
4571  static const char module[] = "MissingRequired";
4572 
4574  "TIFF directory is missing required \"%s\" field",
4575  tagname);
4576 }
thandle_t tif_clientdata
Definition: tiffiop.h:191
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 4585 of file tif_dirread.c.

4586 {
4587  uint16 n;
4588 
4589  if (diroff == 0) /* no more directories */
4590  return 0;
4591  if (tif->tif_dirnumber == 65535) {
4592  TIFFErrorExt(tif->tif_clientdata, "TIFFCheckDirOffset",
4593  "Cannot handle more than 65535 TIFF directories");
4594  return 0;
4595  }
4596 
4597  for (n = 0; n < tif->tif_dirnumber && tif->tif_dirlist; n++) {
4598  if (tif->tif_dirlist[n] == diroff)
4599  return 0;
4600  }
4601 
4602  tif->tif_dirnumber++;
4603 
4604  if (tif->tif_dirlist == NULL || tif->tif_dirnumber > tif->tif_dirlistsize) {
4605  uint64* new_dirlist;
4606 
4607  /*
4608  * XXX: Reduce memory allocation granularity of the dirlist
4609  * array.
4610  */
4611  new_dirlist = (uint64*)_TIFFCheckRealloc(tif, tif->tif_dirlist,
4612  tif->tif_dirnumber, 2 * sizeof(uint64), "for IFD list");
4613  if (!new_dirlist)
4614  return 0;
4615  if( tif->tif_dirnumber >= 32768 )
4616  tif->tif_dirlistsize = 65535;
4617  else
4618  tif->tif_dirlistsize = 2 * tif->tif_dirnumber;
4619  tif->tif_dirlist = new_dirlist;
4620  }
4621 
4622  tif->tif_dirlist[tif->tif_dirnumber - 1] = diroff;
4623 
4624  return 1;
4625 }
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:62
GLdouble n
Definition: glext.h:7729
thandle_t tif_clientdata
Definition: tiffiop.h:191
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:132
uint16 tif_dirnumber
Definition: tiffiop.h:134
unsigned short uint16
Definition: types.h:30
uint16 tif_dirlistsize
Definition: tiffiop.h:133

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 4659 of file tif_dirread.c.

4661 {
4662  static const char module[] = "TIFFFetchDirectory";
4663 
4664  void* origdir;
4665  uint16 dircount16;
4666  uint32 dirsize;
4667  TIFFDirEntry* dir;
4668  uint8* ma;
4669  TIFFDirEntry* mb;
4670  uint16 n;
4671 
4672  assert(pdir);
4673 
4674  tif->tif_diroff = diroff;
4675  if (nextdiroff)
4676  *nextdiroff = 0;
4677  if (!isMapped(tif)) {
4678  if (!SeekOK(tif, tif->tif_diroff)) {
4680  "%s: Seek error accessing TIFF directory",
4681  tif->tif_name);
4682  return 0;
4683  }
4684  if (!(tif->tif_flags&TIFF_BIGTIFF))
4685  {
4686  if (!ReadOK(tif, &dircount16, sizeof (uint16))) {
4688  "%s: Can not read TIFF directory count",
4689  tif->tif_name);
4690  return 0;
4691  }
4692  if (tif->tif_flags & TIFF_SWAB)
4693  TIFFSwabShort(&dircount16);
4694  if (dircount16>4096)
4695  {
4697  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4698  return 0;
4699  }
4700  dirsize = 12;
4701  } else {
4702  uint64 dircount64;
4703  if (!ReadOK(tif, &dircount64, sizeof (uint64))) {
4705  "%s: Can not read TIFF directory count",
4706  tif->tif_name);
4707  return 0;
4708  }
4709  if (tif->tif_flags & TIFF_SWAB)
4710  TIFFSwabLong8(&dircount64);
4711  if (dircount64>4096)
4712  {
4714  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4715  return 0;
4716  }
4717  dircount16 = (uint16)dircount64;
4718  dirsize = 20;
4719  }
4720  origdir = _TIFFCheckMalloc(tif, dircount16,
4721  dirsize, "to read TIFF directory");
4722  if (origdir == NULL)
4723  return 0;
4724  if (!ReadOK(tif, origdir, (tmsize_t)(dircount16*dirsize))) {
4726  "%.100s: Can not read TIFF directory",
4727  tif->tif_name);
4728  _TIFFfree(origdir);
4729  return 0;
4730  }
4731  /*
4732  * Read offset to next directory for sequential scans if
4733  * needed.
4734  */
4735  if (nextdiroff)
4736  {
4737  if (!(tif->tif_flags&TIFF_BIGTIFF))
4738  {
4739  uint32 nextdiroff32;
4740  if (!ReadOK(tif, &nextdiroff32, sizeof(uint32)))
4741  nextdiroff32 = 0;
4742  if (tif->tif_flags&TIFF_SWAB)
4743  TIFFSwabLong(&nextdiroff32);
4744  *nextdiroff=nextdiroff32;
4745  } else {
4746  if (!ReadOK(tif, nextdiroff, sizeof(uint64)))
4747  *nextdiroff = 0;
4748  if (tif->tif_flags&TIFF_SWAB)
4749  TIFFSwabLong8(nextdiroff);
4750  }
4751  }
4752  } else {
4753  tmsize_t m;
4754  tmsize_t off = (tmsize_t) tif->tif_diroff;
4755  if ((uint64)off!=tif->tif_diroff)
4756  {
4757  TIFFErrorExt(tif->tif_clientdata,module,"Can not read TIFF directory count");
4758  return(0);
4759  }
4760 
4761  /*
4762  * Check for integer overflow when validating the dir_off,
4763  * otherwise a very high offset may cause an OOB read and
4764  * crash the client. Make two comparisons instead of
4765  *
4766  * off + sizeof(uint16) > tif->tif_size
4767  *
4768  * to avoid overflow.
4769  */
4770  if (!(tif->tif_flags&TIFF_BIGTIFF))
4771  {
4772  m=off+sizeof(uint16);
4773  if ((m<off)||(m<(tmsize_t)sizeof(uint16))||(m>tif->tif_size)) {
4775  "Can not read TIFF directory count");
4776  return 0;
4777  } else {
4778  _TIFFmemcpy(&dircount16, tif->tif_base + off,
4779  sizeof(uint16));
4780  }
4781  off += sizeof (uint16);
4782  if (tif->tif_flags & TIFF_SWAB)
4783  TIFFSwabShort(&dircount16);
4784  if (dircount16>4096)
4785  {
4787  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4788  return 0;
4789  }
4790  dirsize = 12;
4791  }
4792  else
4793  {
4794  uint64 dircount64;
4795  m=off+sizeof(uint64);
4796  if ((m<off)||(m<(tmsize_t)sizeof(uint64))||(m>tif->tif_size)) {
4798  "Can not read TIFF directory count");
4799  return 0;
4800  } else {
4801  _TIFFmemcpy(&dircount64, tif->tif_base + off,
4802  sizeof(uint64));
4803  }
4804  off += sizeof (uint64);
4805  if (tif->tif_flags & TIFF_SWAB)
4806  TIFFSwabLong8(&dircount64);
4807  if (dircount64>4096)
4808  {
4810  "Sanity check on directory count failed, this is probably not a valid IFD offset");
4811  return 0;
4812  }
4813  dircount16 = (uint16)dircount64;
4814  dirsize = 20;
4815  }
4816  if (dircount16 == 0 )
4817  {
4819  "Sanity check on directory count failed, zero tag directories not supported");
4820  return 0;
4821  }
4822  origdir = _TIFFCheckMalloc(tif, dircount16,
4823  dirsize,
4824  "to read TIFF directory");
4825  if (origdir == NULL)
4826  return 0;
4827  m=off+dircount16*dirsize;
4828  if ((m<off)||(m<(tmsize_t)(dircount16*dirsize))||(m>tif->tif_size)) {
4830  "Can not read TIFF directory");
4831  _TIFFfree(origdir);
4832  return 0;
4833  } else {
4834  _TIFFmemcpy(origdir, tif->tif_base + off,
4835  dircount16 * dirsize);
4836  }
4837  if (nextdiroff) {
4838  off += dircount16 * dirsize;
4839  if (!(tif->tif_flags&TIFF_BIGTIFF))
4840  {
4841  uint32 nextdiroff32;
4842  m=off+sizeof(uint32);
4843  if ((m<off)||(m<(tmsize_t)sizeof(uint32))||(m>tif->tif_size))
4844  nextdiroff32 = 0;
4845  else
4846  _TIFFmemcpy(&nextdiroff32, tif->tif_base + off,
4847  sizeof (uint32));
4848  if (tif->tif_flags&TIFF_SWAB)
4849  TIFFSwabLong(&nextdiroff32);
4850  *nextdiroff = nextdiroff32;
4851  }
4852  else
4853  {
4854  m=off+sizeof(uint64);
4855  if ((m<off)||(m<(tmsize_t)sizeof(uint64))||(m>tif->tif_size))
4856  *nextdiroff = 0;
4857  else
4858  _TIFFmemcpy(nextdiroff, tif->tif_base + off,
4859  sizeof (uint64));
4860  if (tif->tif_flags&TIFF_SWAB)
4861  TIFFSwabLong8(nextdiroff);
4862  }
4863  }
4864  }
4865  dir = (TIFFDirEntry*)_TIFFCheckMalloc(tif, dircount16,
4866  sizeof(TIFFDirEntry),
4867  "to read TIFF directory");
4868  if (dir==0)
4869  {
4870  _TIFFfree(origdir);
4871  return 0;
4872  }
4873  ma=(uint8*)origdir;
4874  mb=dir;
4875  for (n=0; n<dircount16; n++)
4876  {
4877  if (tif->tif_flags&TIFF_SWAB)
4878  TIFFSwabShort((uint16*)ma);
4879  mb->tdir_tag=*(uint16*)ma;
4880  ma+=sizeof(uint16);
4881  if (tif->tif_flags&TIFF_SWAB)
4882  TIFFSwabShort((uint16*)ma);
4883  mb->tdir_type=*(uint16*)ma;
4884  ma+=sizeof(uint16);
4885  if (!(tif->tif_flags&TIFF_BIGTIFF))
4886  {
4887  if (tif->tif_flags&TIFF_SWAB)
4888  TIFFSwabLong((uint32*)ma);
4889  mb->tdir_count=(uint64)(*(uint32*)ma);
4890  ma+=sizeof(uint32);
4891  *(uint32*)(&mb->tdir_offset)=*(uint32*)ma;
4892  ma+=sizeof(uint32);
4893  }
4894  else
4895  {
4896  if (tif->tif_flags&TIFF_SWAB)
4897  TIFFSwabLong8((uint64*)ma);
4898  mb->tdir_count=TIFFReadUInt64(ma);
4899  ma+=sizeof(uint64);
4901  ma+=sizeof(uint64);
4902  }
4903  mb++;
4904  }
4905  _TIFFfree(origdir);
4906  *pdir = dir;
4907  return dircount16;
4908 }
unsigned long long uint64
Definition: platform.h:18
uint8 * tif_base
Definition: tiffiop.h:186
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
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:191
union TIFFDirEntry::@3328 tdir_offset
char * tif_name
Definition: tiffiop.h:103
const GLfloat * m
Definition: glext.h:10848
#define TIFF_BIGTIFF
Definition: tiffiop.h:125
#define TIFF_SWAB
Definition: tiffiop.h:113
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:85
uint32 tif_flags
Definition: tiffiop.h:106
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
#define isMapped(tif)
Definition: tiffiop.h:214
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:130
tmsize_t tif_size
Definition: tiffiop.h:187
static uint64 TIFFReadUInt64(const uint8 *value)
Definition: tif_dirread.c:184
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
unsigned short uint16
Definition: types.h:30
#define SeekOK(tif, off)
Definition: tiffiop.h:240
#define ReadOK(tif, buf, size)
Definition: tiffiop.h:236
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 4914 of file tif_dirread.c.

4915 {
4916  static const char module[] = "TIFFFetchNormalTag";
4917  enum TIFFReadDirEntryErr err;
4918  uint32 fii;
4919  const TIFFField* fip = NULL;
4921  if( fii == FAILED_FII )
4922  {
4923  TIFFErrorExt(tif->tif_clientdata, "TIFFFetchNormalTag",
4924  "No definition found for tag %d",
4925  dp->tdir_tag);
4926  return 0;
4927  }
4928  fip=tif->tif_fields[fii];
4929  assert(fip != NULL); /* should not happen */
4930  assert(fip->set_field_type!=TIFF_SETGET_OTHER); /* if so, we shouldn't arrive here but deal with this in specialized code */
4931  assert(fip->set_field_type!=TIFF_SETGET_INT); /* if so, we shouldn't arrive here as this is only the case for pseudo-tags */
4933  switch (fip->set_field_type)
4934  {
4935  case TIFF_SETGET_UNDEFINED:
4936  break;
4937  case TIFF_SETGET_ASCII:
4938  {
4939  uint8* data;
4940  assert(fip->field_passcount==0);
4943  {
4944  uint32 mb = 0;
4945  int n;
4946  if (data != NULL)
4947  {
4948  uint8* ma = data;
4949  while (mb<(uint32)dp->tdir_count)
4950  {
4951  if (*ma==0)
4952  break;
4953  ma++;
4954  mb++;
4955  }
4956  }
4957  if (mb+1<(uint32)dp->tdir_count)
4958  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);
4959  else if (mb+1>(uint32)dp->tdir_count)
4960  {
4961  uint8* o;
4962  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte",fip->field_name);
4963  if ((uint32)dp->tdir_count+1!=dp->tdir_count+1)
4964  o=NULL;
4965  else
4966  o=_TIFFmalloc((uint32)dp->tdir_count+1);
4967  if (o==NULL)
4968  {
4969  if (data!=NULL)
4970  _TIFFfree(data);
4971  return(0);
4972  }
4974  o[(uint32)dp->tdir_count]=0;
4975  if (data!=0)
4976  _TIFFfree(data);
4977  data=o;
4978  }
4979  n=TIFFSetField(tif,dp->tdir_tag,data);
4980  if (data!=0)
4981  _TIFFfree(data);
4982  if (!n)
4983  return(0);
4984  }
4985  }
4986  break;
4987  case TIFF_SETGET_UINT8:
4988  {
4989  uint8 data=0;
4990  assert(fip->field_readcount==1);
4991  assert(fip->field_passcount==0);
4992  err=TIFFReadDirEntryByte(tif,dp,&data);
4994  {
4995  if (!TIFFSetField(tif,dp->tdir_tag,data))
4996  return(0);
4997  }
4998  }
4999  break;
5000  case TIFF_SETGET_UINT16:
5001  {
5002  uint16 data;
5003  assert(fip->field_readcount==1);
5004  assert(fip->field_passcount==0);
5005  err=TIFFReadDirEntryShort(tif,dp,&data);
5007  {
5008  if (!TIFFSetField(tif,dp->tdir_tag,data))
5009  return(0);
5010  }
5011  }
5012  break;
5013  case TIFF_SETGET_UINT32:
5014  {
5015  uint32 data;
5016  assert(fip->field_readcount==1);
5017  assert(fip->field_passcount==0);
5018  err=TIFFReadDirEntryLong(tif,dp,&data);
5020  {
5021  if (!TIFFSetField(tif,dp->tdir_tag,data))
5022  return(0);
5023  }
5024  }
5025  break;
5026  case TIFF_SETGET_UINT64:
5027  {
5028  uint64 data;
5029  assert(fip->field_readcount==1);
5030  assert(fip->field_passcount==0);
5031  err=TIFFReadDirEntryLong8(tif,dp,&data);
5033  {
5034  if (!TIFFSetField(tif,dp->tdir_tag,data))
5035  return(0);
5036  }
5037  }
5038  break;
5039  case TIFF_SETGET_FLOAT:
5040  {
5041  float data;
5042  assert(fip->field_readcount==1);
5043  assert(fip->field_passcount==0);
5044  err=TIFFReadDirEntryFloat(tif,dp,&data);
5046  {
5047  if (!TIFFSetField(tif,dp->tdir_tag,data))
5048  return(0);
5049  }
5050  }
5051  break;
5052  case TIFF_SETGET_DOUBLE:
5053  {
5054  double data;
5055  assert(fip->field_readcount==1);
5056  assert(fip->field_passcount==0);
5057  err=TIFFReadDirEntryDouble(tif,dp,&data);
5059  {
5060  if (!TIFFSetField(tif,dp->tdir_tag,data))
5061  return(0);
5062  }
5063  }
5064  break;
5065  case TIFF_SETGET_IFD8:
5066  {
5067  uint64 data;
5068  assert(fip->field_readcount==1);
5069  assert(fip->field_passcount==0);
5070  err=TIFFReadDirEntryIfd8(tif,dp,&data);
5072  {
5073  if (!TIFFSetField(tif,dp->tdir_tag,data))
5074  return(0);
5075  }
5076  }
5077  break;
5079  {
5080  uint16* data;
5081  assert(fip->field_readcount==2);
5082  assert(fip->field_passcount==0);
5083  if (dp->tdir_count!=2) {
5084  TIFFWarningExt(tif->tif_clientdata,module,
5085  "incorrect count for field \"%s\", expected 2, got %d",
5086  fip->field_name,(int)dp->tdir_count);
5087  return(0);
5088  }
5091  {
5092  int m;
5093  m=TIFFSetField(tif,dp->tdir_tag,data[0],data[1]);
5094  _TIFFfree(data);
5095  if (!m)
5096  return(0);
5097  }
5098  }
5099  break;
5100  case TIFF_SETGET_C0_UINT8:
5101  {
5102  uint8* data;
5103  assert(fip->field_readcount>=1);
5104  assert(fip->field_passcount==0);
5105  if (dp->tdir_count!=(uint64)fip->field_readcount) {
5106  TIFFWarningExt(tif->tif_clientdata,module,
5107  "incorrect count for field \"%s\", expected %d, got %d",
5108  fip->field_name,(int) fip->field_readcount, (int)dp->tdir_count);
5109  return 0;
5110  }
5111  else
5112  {
5115  {
5116  int m;
5117  m=TIFFSetField(tif,dp->tdir_tag,data);
5118  if (data!=0)
5119  _TIFFfree(data);
5120  if (!m)
5121  return(0);
5122  }
5123  }
5124  }
5125  break;
5126  case TIFF_SETGET_C0_UINT16:
5127  {
5128  uint16* data;
5129  assert(fip->field_readcount>=1);
5130  assert(fip->field_passcount==0);
5131  if (dp->tdir_count!=(uint64)fip->field_readcount)
5132  /* corrupt file */;
5133  else
5134  {
5137  {
5138  int m;
5139  m=TIFFSetField(tif,dp->tdir_tag,data);
5140  if (data!=0)
5141  _TIFFfree(data);
5142  if (!m)
5143  return(0);
5144  }
5145  }
5146  }
5147  break;
5148  case TIFF_SETGET_C0_UINT32:
5149  {
5150  uint32* data;
5151  assert(fip->field_readcount>=1);
5152  assert(fip->field_passcount==0);
5153  if (dp->tdir_count!=(uint64)fip->field_readcount)
5154  /* corrupt file */;
5155  else
5156  {
5159  {
5160  int m;
5161  m=TIFFSetField(tif,dp->tdir_tag,data);
5162  if (data!=0)
5163  _TIFFfree(data);
5164  if (!m)
5165  return(0);
5166  }
5167  }
5168  }
5169  break;
5170  case TIFF_SETGET_C0_FLOAT:
5171  {
5172  float* data;
5173  assert(fip->field_readcount>=1);
5174  assert(fip->field_passcount==0);
5175  if (dp->tdir_count!=(uint64)fip->field_readcount)
5176  /* corrupt file */;
5177  else
5178  {
5181  {
5182  int m;
5183  m=TIFFSetField(tif,dp->tdir_tag,data);
5184  if (data!=0)
5185  _TIFFfree(data);
5186  if (!m)
5187  return(0);
5188  }
5189  }
5190  }
5191  break;
5192  case TIFF_SETGET_C16_ASCII:
5193  {
5194  uint8* data;
5196  assert(fip->field_passcount==1);
5197  if (dp->tdir_count>0xFFFF)
5199  else
5200  {
5203  {
5204  int m;
5205  if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
5206  {
5207  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
5208  data[dp->tdir_count-1] = '\0';
5209  }
5210  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5211  if (data!=0)
5212  _TIFFfree(data);
5213  if (!m)
5214  return(0);
5215  }
5216  }
5217  }
5218  break;
5219  case TIFF_SETGET_C16_UINT8:
5220  {
5221  uint8* data;
5223  assert(fip->field_passcount==1);
5224  if (dp->tdir_count>0xFFFF)
5226  else
5227  {
5230  {
5231  int m;
5232  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5233  if (data!=0)
5234  _TIFFfree(data);
5235  if (!m)
5236  return(0);
5237  }
5238  }
5239  }
5240  break;
5242  {
5243  uint16* data;
5245  assert(fip->field_passcount==1);
5246  if (dp->tdir_count>0xFFFF)
5248  else
5249  {
5252  {
5253  int m;
5254  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5255  if (data!=0)
5256  _TIFFfree(data);
5257  if (!m)
5258  return(0);
5259  }
5260  }
5261  }
5262  break;
5264  {
5265  uint32* data;
5267  assert(fip->field_passcount==1);
5268  if (dp->tdir_count>0xFFFF)
5270  else
5271  {
5274  {
5275  int m;
5276  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5277  if (data!=0)
5278  _TIFFfree(data);
5279  if (!m)
5280  return(0);
5281  }
5282  }
5283  }
5284  break;
5286  {
5287  uint64* data;
5289  assert(fip->field_passcount==1);
5290  if (dp->tdir_count>0xFFFF)
5292  else
5293  {
5296  {
5297  int m;
5298  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5299  if (data!=0)
5300  _TIFFfree(data);
5301  if (!m)
5302  return(0);
5303  }
5304  }
5305  }
5306  break;
5307  case TIFF_SETGET_C16_FLOAT:
5308  {
5309  float* data;
5311  assert(fip->field_passcount==1);
5312  if (dp->tdir_count>0xFFFF)
5314  else
5315  {
5318  {
5319  int m;
5320  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5321  if (data!=0)
5322  _TIFFfree(data);
5323  if (!m)
5324  return(0);
5325  }
5326  }
5327  }
5328  break;
5330  {
5331  double* data;
5333  assert(fip->field_passcount==1);
5334  if (dp->tdir_count>0xFFFF)
5336  else
5337  {
5340  {
5341  int m;
5342  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5343  if (data!=0)
5344  _TIFFfree(data);
5345  if (!m)
5346  return(0);
5347  }
5348  }
5349  }
5350  break;
5351  case TIFF_SETGET_C16_IFD8:
5352  {
5353  uint64* data;
5355  assert(fip->field_passcount==1);
5356  if (dp->tdir_count>0xFFFF)
5358  else
5359  {
5362  {
5363  int m;
5364  m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
5365  if (data!=0)
5366  _TIFFfree(data);
5367  if (!m)
5368  return(0);
5369  }
5370  }
5371  }
5372  break;
5373  case TIFF_SETGET_C32_ASCII:
5374  {
5375  uint8* data;
5377  assert(fip->field_passcount==1);
5380  {
5381  int m;
5382  if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
5383  {
5384  TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
5385  data[dp->tdir_count-1] = '\0';
5386  }
5387  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5388  if (data!=0)
5389  _TIFFfree(data);
5390  if (!m)
5391  return(0);
5392  }
5393  }
5394  break;
5395  case TIFF_SETGET_C32_UINT8:
5396  {
5397  uint8* data;
5399  assert(fip->field_passcount==1);
5402  {
5403  int m;
5404  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5405  if (data!=0)
5406  _TIFFfree(data);
5407  if (!m)
5408  return(0);
5409  }
5410  }
5411  break;
5412  case TIFF_SETGET_C32_SINT8:
5413  {
5414  int8* data = NULL;
5416  assert(fip->field_passcount==1);
5419  {
5420  int m;
5421  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5422  if (data!=0)
5423  _TIFFfree(data);
5424  if (!m)
5425  return(0);
5426  }
5427  }
5428  break;
5430  {
5431  uint16* data;
5433  assert(fip->field_passcount==1);
5436  {
5437  int m;
5438  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5439  if (data!=0)
5440  _TIFFfree(data);
5441  if (!m)
5442  return(0);
5443  }
5444  }
5445  break;
5447  {
5448  int16* data = NULL;
5450  assert(fip->field_passcount==1);
5453  {
5454  int m;
5455  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5456  if (data!=0)
5457  _TIFFfree(data);
5458  if (!m)
5459  return(0);
5460  }
5461  }
5462  break;
5464  {
5465  uint32* data;
5467  assert(fip->field_passcount==1);
5470  {
5471  int m;
5472  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5473  if (data!=0)
5474  _TIFFfree(data);
5475  if (!m)
5476  return(0);
5477  }
5478  }
5479  break;
5481  {
5482  int32* data = NULL;
5484  assert(fip->field_passcount==1);
5487  {
5488  int m;
5489  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5490  if (data!=0)
5491  _TIFFfree(data);
5492  if (!m)
5493  return(0);
5494  }
5495  }
5496  break;
5498  {
5499  uint64* data;
5501  assert(fip->field_passcount==1);
5504  {
5505  int m;
5506  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5507  if (data!=0)
5508  _TIFFfree(data);
5509  if (!m)
5510  return(0);
5511  }
5512  }
5513  break;
5515  {
5516  int64* data = NULL;
5518  assert(fip->field_passcount==1);
5521  {
5522  int m;
5523  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5524  if (data!=0)
5525  _TIFFfree(data);
5526  if (!m)
5527  return(0);
5528  }
5529  }
5530  break;
5531  case TIFF_SETGET_C32_FLOAT:
5532  {
5533  float* data;
5535  assert(fip->field_passcount==1);
5538  {
5539  int m;
5540  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5541  if (data!=0)
5542  _TIFFfree(data);
5543  if (!m)
5544  return(0);
5545  }
5546  }
5547  break;
5549  {
5550  double* data;
5552  assert(fip->field_passcount==1);
5555  {
5556  int m;
5557  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5558  if (data!=0)
5559  _TIFFfree(data);
5560  if (!m)
5561  return(0);
5562  }
5563  }
5564  break;
5565  case TIFF_SETGET_C32_IFD8:
5566  {
5567  uint64* data;
5569  assert(fip->field_passcount==1);
5572  {
5573  int m;
5574  m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
5575  if (data!=0)
5576  _TIFFfree(data);
5577  if (!m)
5578  return(0);
5579  }
5580  }
5581  break;
5582  default:
5583  assert(0); /* we should never get here */
5584  break;
5585  }
5587  {
5588  TIFFReadDirEntryOutputErr(tif,err,module,fip->field_name,recover);
5589  return(0);
5590  }
5591  return(1);
5592 }
unsigned long long uint64
Definition: platform.h:18
return
Definition: dirsup.c:529
#define TIFF_VARIABLE
Definition: tiffio.h:313
static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray(TIFF *tif, TIFFDirEntry *direntry, int8 **value)
Definition: tif_dirread.c:1112
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4327
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
Definition: tif_warning.c:65
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
Definition: tif_dirread.c:2527
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:1630
thandle_t tif_clientdata
Definition: tiffiop.h:191
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:2132
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong(TIFF *tif, TIFFDirEntry *direntry, uint32 *value)
Definition: tif_dirread.c:375
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
Definition: tif_dirread.c:746
char * field_name
Definition: tif_dir.h:289
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray(TIFF *tif, TIFFDirEntry *direntry, int32 **value)
Definition: tif_dirread.c:1799
static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray(TIFF *tif, TIFFDirEntry *direntry, uint8 **value)
Definition: tif_dirread.c:931
#define FAILED_FII
Definition: tif_dirread.c:45
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:2764
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array(TIFF *tif, TIFFDirEntry *direntry, uint64 **value)
Definition: tif_dirread.c:2127
unsigned char field_passcount
Definition: tif_dir.h:288
static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble(TIFF *tif, TIFFDirEntry *direntry, double *value)
Definition: tif_dirread.c:649
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:1463
#define err(...)
TIFFField ** tif_fields
Definition: tiffiop.h:200
#define TIFF_VARIABLE2
Definition: tiffio.h:315
TIFFSetGetFieldType set_field_type
Definition: tif_dir.h:284
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray(TIFF *tif, TIFFDirEntry *direntry, float **value)
Definition: tif_dirread.c:2282
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:536
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:289
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8(TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
Definition: tif_dirread.c:458
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:3421
void _TIFFfree(void *p)
Definition: tif_unix.c:326
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF *tif, TIFFDirEntry *direntry, uint16 **value)
Definition: tif_dirread.c:1291
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:790
static enum TIFFReadDirEntryErr TIFFReadDirEntryByte(TIFF *tif, TIFFDirEntry *direntry, uint8 *value)
Definition: tif_dirread.c:200
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:280

Referenced by TIFFReadCustomDirectory(), and TIFFReadDirectory().

◆ TIFFFetchStripThing()

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

Definition at line 5599 of file tif_dirread.c.

5600 {
5601  static const char module[] = "TIFFFetchStripThing";
5602  enum TIFFReadDirEntryErr err;
5603  uint64* data;
5606  {
5607  const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);
5608  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
5609  return(0);
5610  }
5611  if (dir->tdir_count<(uint64)nstrips)
5612  {
5613  uint64* resizeddata;
5614  const TIFFField* fip = TIFFFieldWithTag(tif,dir->tdir_tag);
5615  const char* pszMax = getenv("LIBTIFF_STRILE_ARRAY_MAX_RESIZE_COUNT");
5616  uint32 max_nstrips = 1000000;
5617  if( pszMax )
5618  max_nstrips = (uint32) atoi(pszMax);
5620  module,
5621  fip ? fip->field_name : "unknown tagname",
5622  ( nstrips <= max_nstrips ) );
5623 
5624  if( nstrips > max_nstrips )
5625  {
5626  _TIFFfree(data);
5627  return(0);
5628  }
5629 
5630  resizeddata=(uint64*)_TIFFCheckMalloc(tif,nstrips,sizeof(uint64),"for strip array");
5631  if (resizeddata==0) {
5632  _TIFFfree(data);
5633  return(0);
5634  }
5635  _TIFFmemcpy(resizeddata,data,(uint32)dir->tdir_count*sizeof(uint64));
5636  _TIFFmemset(resizeddata+(uint32)dir->tdir_count,0,(nstrips-(uint32)dir->tdir_count)*sizeof(uint64));
5637  _TIFFfree(data);
5638  data=resizeddata;
5639  }
5640  *lpp=data;
5641  return(1);
5642 }
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:55
unsigned int uint32
Definition: types.h:32
char * field_name
Definition: tif_dir.h:289
void * _TIFFCheckMalloc(TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
Definition: tif_aux.c:85
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:3421
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:1960
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 5648 of file tif_dirread.c.

5649 {
5650  static const char module[] = "TIFFFetchSubjectDistance";
5651  enum TIFFReadDirEntryErr err;
5653  m.l=0;
5654  assert(sizeof(double)==8);
5655  assert(sizeof(uint64)==8);
5656  assert(sizeof(uint32)==4);
5657  if (dir->tdir_count!=1)
5659  else if (dir->tdir_type!=TIFF_RATIONAL)
5661  else
5662  {
5663  if (!(tif->tif_flags&TIFF_BIGTIFF))
5664  {
5665  uint32 offset;
5666  offset=*(uint32*)(&dir->tdir_offset);
5667  if (tif->tif_flags&TIFF_SWAB)
5668  TIFFSwabLong(&offset);
5669  err=TIFFReadDirEntryData(tif,offset,8,m.i);
5670  }
5671  else
5672  {
5673  m.l=dir->tdir_offset.toff_long8;
5675  }
5676  }
5678  {
5679  double n;
5680  if (tif->tif_flags&TIFF_SWAB)
5681  TIFFSwabArrayOfLong(m.i,2);
5682  if (m.i[0]==0)
5683  n=0.0;
5684  else if (m.i[0]==0xFFFFFFFF)
5685  /*
5686  * XXX: Numerator 0xFFFFFFFF means that we have infinite
5687  * distance. Indicate that with a negative floating point
5688  * SubjectDistance value.
5689  */
5690  n=-1.0;
5691  else
5692  n=(double)m.i[0]/(double)m.i[1];
5693  return(TIFFSetField(tif,dir->tdir_tag,n));
5694  }
5695  else
5696  {
5697  TIFFReadDirEntryOutputErr(tif,err,module,"SubjectDistance",TRUE);
5698  return(0);
5699  }
5700 }
unsigned long long uint64
Definition: platform.h:18
#define TRUE
Definition: types.h:120
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
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:125
#define TIFF_SWAB
Definition: tiffiop.h:113
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:106
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:3397
#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:3421
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:790

Referenced by TIFFReadCustomDirectory().

◆ TIFFReadCustomDirectory()

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

Definition at line 4363 of file tif_dirread.c.

4365 {
4366  static const char module[] = "TIFFReadCustomDirectory";
4367  TIFFDirEntry* dir;
4368  uint16 dircount;
4369  TIFFDirEntry* dp;
4370  uint16 di;
4371  const TIFFField* fip;
4372  uint32 fii;
4373  _TIFFSetupFields(tif, infoarray);
4374  dircount=TIFFFetchDirectory(tif,diroff,&dir,NULL);
4375  if (!dircount)
4376  {
4378  "Failed to read custom directory at offset " TIFF_UINT64_FORMAT,diroff);
4379  return 0;
4380  }
4381  TIFFFreeDirectory(tif);
4382  _TIFFmemset(&tif->tif_dir, 0, sizeof(TIFFDirectory));
4383  TIFFReadDirectoryCheckOrder(tif,dir,dircount);
4384  for (di=0, dp=dir; di<dircount; di++, dp++)
4385  {
4387  if (fii == FAILED_FII)
4388  {
4390  "Unknown field with tag %d (0x%x) encountered",
4391  dp->tdir_tag, dp->tdir_tag);
4392  if (!_TIFFMergeFields(tif, _TIFFCreateAnonField(tif,
4393  dp->tdir_tag,
4394  (TIFFDataType) dp->tdir_type),
4395  1)) {
4397  "Registering anonymous field with tag %d (0x%x) failed",
4398  dp->tdir_tag, dp->tdir_tag);
4399  dp->tdir_tag=IGNORE;
4400  } else {
4402  assert( fii != FAILED_FII );
4403  }
4404  }
4405  if (dp->tdir_tag!=IGNORE)
4406  {
4407  fip=tif->tif_fields[fii];
4408  if (fip->field_bit==FIELD_IGNORE)
4409  dp->tdir_tag=IGNORE;
4410  else
4411  {
4412  /* check data type */
4413  while ((fip->field_type!=TIFF_ANY)&&(fip->field_type!=dp->tdir_type))
4414  {
4415  fii++;
4416  if ((fii==tif->tif_nfields)||
4417  (tif->tif_fields[fii]->field_tag!=(uint32)dp->tdir_tag))
4418  {
4419  fii=0xFFFF;
4420  break;
4421  }
4422  fip=tif->tif_fields[fii];
4423  }
4424  if (fii==0xFFFF)
4425  {
4427  "Wrong data type %d for \"%s\"; tag ignored",
4428  dp->tdir_type,fip->field_name);
4429  dp->tdir_tag=IGNORE;
4430  }
4431  else
4432  {
4433  /* check count if known in advance */
4434  if ((fip->field_readcount!=TIFF_VARIABLE)&&
4436  {
4437  uint32 expected;
4438  if (fip->field_readcount==TIFF_SPP)
4440  else
4442  if (!CheckDirCount(tif,dp,expected))
4443  dp->tdir_tag=IGNORE;
4444  }
4445  }
4446  }
4447  switch (dp->tdir_tag)
4448  {
4449  case IGNORE:
4450  break;
4452  (void) TIFFFetchSubjectDistance(tif,dp);
4453  break;
4454  default:
4455  (void) TIFFFetchNormalTag(tif, dp, TRUE);
4456  break;
4457  }
4458  }
4459  }
4460  if (dir)
4461  _TIFFfree(dir);
4462  return 1;
4463 }
void _TIFFmemset(void *p, int v, tmsize_t c)
Definition: tif_unix.c:338
#define FIELD_IGNORE
Definition: tif_dir.h:134
#define TIFF_VARIABLE
Definition: tiffio.h:313
#define TRUE
Definition: types.h:120
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4327
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:312
static int CheckDirCount(TIFF *, TIFFDirEntry *, uint32)
Definition: tif_dirread.c:4632
unsigned int uint32
Definition: types.h:32
static int TIFFFetchNormalTag(TIFF *, TIFFDirEntry *, int recover)
Definition: tif_dirread.c:4914
#define assert(x)
Definition: debug.h:53
thandle_t tif_clientdata
Definition: tiffiop.h:191
#define IGNORE
Definition: tif_dirread.c:44
unsigned short field_bit
Definition: tif_dir.h:286
static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
Definition: tif_dirread.c:4293
char * field_name
Definition: tif_dir.h:289
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32 n)
Definition: tif_dirinfo.c:369
#define FAILED_FII
Definition: tif_dirread.c:45
smooth NULL
Definition: ftsmooth.c:416
size_t tif_nfields
Definition: tiffiop.h:201
unsigned int dir
Definition: maze.c:112
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1251
void _TIFFSetupFields(TIFF *tif, const TIFFFieldArray *fieldarray)
Definition: tif_dirinfo.c:317
uint32 field_tag
Definition: tif_dir.h:279
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:200
#define TIFF_VARIABLE2
Definition: tiffio.h:315
TIFFDataType field_type
Definition: tif_dir.h:282
#define TIFF_SPP
Definition: tiffio.h:314
unsigned short uint16
Definition: types.h:30
TIFFDirectory tif_dir
Definition: tiffiop.h:135
static int TIFFFetchSubjectDistance(TIFF *, TIFFDirEntry *)
Definition: tif_dirread.c:5648
uint16 td_samplesperpixel
Definition: tif_dir.h:81
void _TIFFfree(void *p)
Definition: tif_unix.c:326
static uint16 TIFFFetchDirectory(TIFF *tif, uint64 diroff, TIFFDirEntry **pdir, uint64 *nextdiroff)
Definition: tif_dirread.c:4659
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:280

Referenced by TIFFReadEXIFDirectory().

◆ TIFFReadDirectory()

int TIFFReadDirectory ( TIFF tif)

Definition at line 3542 of file tif_dirread.c.

3543 {
3544  static const char module[] = "TIFFReadDirectory";
3545  TIFFDirEntry* dir;
3546  uint16 dircount;
3547  TIFFDirEntry* dp;
3548  uint16 di;
3549  const TIFFField* fip;
3550  uint32 fii=FAILED_FII;
3551  toff_t nextdiroff;
3552  int bitspersample_read = FALSE;
3553  int color_channels;
3554 
3555  tif->tif_diroff=tif->tif_nextdiroff;
3556  if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
3557  return 0; /* last offset or bad offset (IFD looping) */
3558  (*tif->tif_cleanup)(tif); /* cleanup any previous compression state */
3559  tif->tif_curdir++;
3560  nextdiroff = tif->tif_nextdiroff;
3561  dircount=TIFFFetchDirectory(tif,nextdiroff,&dir,&tif->tif_nextdiroff);
3562  if (!dircount)
3563  {
3565  "Failed to read directory at offset " TIFF_UINT64_FORMAT,nextdiroff);
3566  return 0;
3567  }
3568  TIFFReadDirectoryCheckOrder(tif,dir,dircount);
3569 
3570  /*
3571  * Mark duplicates of any tag to be ignored (bugzilla 1994)
3572  * to avoid certain pathological problems.
3573  */
3574  {
3575  TIFFDirEntry* ma;
3576  uint16 mb;
3577  for (ma=dir, mb=0; mb<dircount; ma++, mb++)
3578  {
3579  TIFFDirEntry* na;
3580  uint16 nb;
3581  for (na=ma+1, nb=mb+1; nb<dircount; na++, nb++)
3582  {
3583  if (ma->tdir_tag==na->tdir_tag)
3584  na->tdir_tag=IGNORE;
3585  }
3586  }
3587  }
3588 
3589  tif->tif_flags &= ~TIFF_BEENWRITING; /* reset before new dir */
3590  tif->tif_flags &= ~TIFF_BUF4WRITE; /* reset before new dir */
3591  /* free any old stuff and reinit */
3592  TIFFFreeDirectory(tif);
3593  TIFFDefaultDirectory(tif);
3594  /*
3595  * Electronic Arts writes gray-scale TIFF files
3596  * without a PlanarConfiguration directory entry.
3597  * Thus we setup a default value here, even though
3598  * the TIFF spec says there is no default value.
3599  */
3601  /*
3602  * Setup default value and then make a pass over
3603  * the fields to check type and tag information,
3604  * and to extract info required to size data
3605  * structures. A second pass is made afterwards
3606  * to read in everything not taken in the first pass.
3607  * But we must process the Compression tag first
3608  * in order to merge in codec-private tag definitions (otherwise
3609  * we may get complaints about unknown tags). However, the
3610  * Compression tag may be dependent on the SamplesPerPixel
3611  * tag value because older TIFF specs permitted Compression
3612  * to be written as a SamplesPerPixel-count tag entry.
3613  * Thus if we don't first figure out the correct SamplesPerPixel
3614  * tag value then we may end up ignoring the Compression tag
3615  * value because it has an incorrect count value (if the
3616  * true value of SamplesPerPixel is not 1).
3617  */
3619  if (dp)
3620  {
3621  if (!TIFFFetchNormalTag(tif,dp,0))
3622  goto bad;
3623  dp->tdir_tag=IGNORE;
3624  }
3626  if (dp)
3627  {
3628  /*
3629  * The 5.0 spec says the Compression tag has one value, while
3630  * earlier specs say it has one value per sample. Because of
3631  * this, we accept the tag if one value is supplied with either
3632  * count.
3633  */
3634  uint16 value;
3635  enum TIFFReadDirEntryErr err;
3636  err=TIFFReadDirEntryShort(tif,dp,&value);
3640  {
3641  TIFFReadDirEntryOutputErr(tif,err,module,"Compression",0);
3642  goto bad;
3643  }
3645  goto bad;
3646  dp->tdir_tag=IGNORE;
3647  }
3648  else
3649  {
3651  goto bad;
3652  }
3653  /*
3654  * First real pass over the directory.
3655  */
3656  for (di=0, dp=dir; di<dircount; di++, dp++)
3657  {
3658  if (dp->tdir_tag!=IGNORE)
3659  {
3661  if (fii == FAILED_FII)
3662  {
3664  "Unknown field with tag %d (0x%x) encountered",
3665  dp->tdir_tag,dp->tdir_tag);
3666  /* the following knowingly leaks the
3667  anonymous field structure */
3668  if (!_TIFFMergeFields(tif,
3670  dp->tdir_tag,
3671  (TIFFDataType) dp->tdir_type),
3672  1)) {
3674  module,
3675  "Registering anonymous field with tag %d (0x%x) failed",
3676  dp->tdir_tag,
3677  dp->tdir_tag);
3678  dp->tdir_tag=IGNORE;
3679  } else {
3681  assert(fii != FAILED_FII);
3682  }
3683  }
3684  }
3685  if (dp->tdir_tag!=IGNORE)
3686  {
3687  fip=tif->tif_fields[fii];
3688  if (fip->field_bit==FIELD_IGNORE)
3689  dp->tdir_tag=IGNORE;
3690  else
3691  {
3692  switch (dp->tdir_tag)
3693  {
3694  case TIFFTAG_STRIPOFFSETS:
3696  case TIFFTAG_TILEOFFSETS:
3698  TIFFSetFieldBit(tif,fip->field_bit);
3699  break;
3700  case TIFFTAG_IMAGEWIDTH:
3701  case TIFFTAG_IMAGELENGTH:
3702  case TIFFTAG_IMAGEDEPTH:
3703  case TIFFTAG_TILELENGTH:
3704  case TIFFTAG_TILEWIDTH:
3705  case TIFFTAG_TILEDEPTH:
3706  case TIFFTAG_PLANARCONFIG:
3707  case TIFFTAG_ROWSPERSTRIP:
3708  case TIFFTAG_EXTRASAMPLES:
3709  if (!TIFFFetchNormalTag(tif,dp,0))
3710  goto bad;
3711  dp->tdir_tag=IGNORE;
3712  break;
3713  default:
3714  if( !_TIFFCheckFieldIsValidForCodec(tif, dp->tdir_tag) )
3715  dp->tdir_tag=IGNORE;
3716  break;
3717  }
3718  }
3719  }
3720  }
3721  /*
3722  * XXX: OJPEG hack.
3723  * If a) compression is OJPEG, b) planarconfig tag says it's separate,
3724  * c) strip offsets/bytecounts tag are both present and
3725  * d) both contain exactly one value, then we consistently find
3726  * that the buggy implementation of the buggy compression scheme
3727  * matches contig planarconfig best. So we 'fix-up' the tag here
3728  */
3731  {
3732  if (!_TIFFFillStriles(tif))
3733  goto bad;
3735  if ((dp!=0)&&(dp->tdir_count==1))
3736  {
3737  dp=TIFFReadDirectoryFindEntry(tif,dir,dircount,
3739  if ((dp!=0)&&(dp->tdir_count==1))
3740  {
3743  "Planarconfig tag value assumed incorrect, "
3744  "assuming data is contig instead of chunky");
3745  }
3746  }
3747  }
3748  /*
3749  * Allocate directory structure and setup defaults.
3750  */
3752  {
3753  MissingRequired(tif,"ImageLength");
3754  goto bad;
3755  }
3756  /*
3757  * Setup appropriate structures (by strip or by tile)
3758  */
3759  if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) {
3760  tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif);
3764  tif->tif_flags &= ~TIFF_ISTILED;
3765  } else {
3766  tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif);
3767  tif->tif_flags |= TIFF_ISTILED;
3768  }
3769  if (!tif->tif_dir.td_nstrips) {
3771  "Cannot handle zero number of %s",
3772  isTiled(tif) ? "tiles" : "strips");
3773  goto bad;
3774  }
3778  if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) {
3779 #ifdef OJPEG_SUPPORT
3781  (isTiled(tif)==0) &&
3782  (tif->tif_dir.td_nstrips==1)) {
3783  /*
3784  * XXX: OJPEG hack.
3785  * If a) compression is OJPEG, b) it's not a tiled TIFF,
3786  * and c) the number of strips is 1,
3787  * then we tolerate the absence of stripoffsets tag,
3788  * because, presumably, all required data is in the
3789  * JpegInterchangeFormat stream.
3790  */
3792  } else
3793 #endif
3794  {
3795  MissingRequired(tif,
3796  isTiled(tif) ? "TileOffsets" : "StripOffsets");
3797  goto bad;
3798  }
3799  }
3800  /*
3801  * Second pass: extract other information.
3802  */
3803  for (di=0, dp=dir; di<dircount; di++, dp++)
3804  {
3805  switch (dp->tdir_tag)
3806  {
3807  case IGNORE:
3808  break;
3811  case TIFFTAG_BITSPERSAMPLE:
3812  case TIFFTAG_DATATYPE:
3813  case TIFFTAG_SAMPLEFORMAT:
3814  /*
3815  * The MinSampleValue, MaxSampleValue, BitsPerSample
3816  * DataType and SampleFormat tags are supposed to be
3817  * written as one value/sample, but some vendors
3818  * incorrectly write one value only -- so we accept
3819  * that as well (yuck). Other vendors write correct
3820  * value for NumberOfSamples, but incorrect one for
3821  * BitsPerSample and friends, and we will read this
3822  * too.
3823  */
3824  {
3825  uint16 value;
3826  enum TIFFReadDirEntryErr err;
3827  err=TIFFReadDirEntryShort(tif,dp,&value);
3831  {
3832  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3833  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
3834  goto bad;
3835  }
3836  if (!TIFFSetField(tif,dp->tdir_tag,value))
3837  goto bad;
3838  if( dp->tdir_tag == TIFFTAG_BITSPERSAMPLE )
3839  bitspersample_read = TRUE;
3840  }
3841  break;
3844  {
3845 
3846  double *data = NULL;
3847  enum TIFFReadDirEntryErr err;
3848  uint32 saved_flags;
3849  int m;
3850  if (dp->tdir_count != (uint64)tif->tif_dir.td_samplesperpixel)
3852  else
3853  err = TIFFReadDirEntryDoubleArray(tif, dp, &data);
3855  {
3856  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3857  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",0);
3858  goto bad;
3859  }
3860  saved_flags = tif->tif_flags;
3861  tif->tif_flags |= TIFF_PERSAMPLE;
3862  m = TIFFSetField(tif,dp->tdir_tag,data);
3863  tif->tif_flags = saved_flags;
3864  _TIFFfree(data);
3865  if (!m)
3866  goto bad;
3867  }
3868  break;
3869  case TIFFTAG_STRIPOFFSETS:
3870  case TIFFTAG_TILEOFFSETS:
3871 #if defined(DEFER_STRILE_LOAD)
3872  _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry),
3873  dp, sizeof(TIFFDirEntry) );
3874 #else
3875  if( tif->tif_dir.td_stripoffset != NULL )
3876  {
3878  "tif->tif_dir.td_stripoffset is "
3879  "already allocated. Likely duplicated "
3880  "StripOffsets/TileOffsets tag");
3881  goto bad;
3882  }
3883  if (!TIFFFetchStripThing(tif,dp,tif->tif_dir.td_nstrips,&tif->tif_dir.td_stripoffset))
3884  goto bad;
3885 #endif
3886  break;
3889 #if defined(DEFER_STRILE_LOAD)
3890  _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry),
3891  dp, sizeof(TIFFDirEntry) );
3892 #else
3893  if( tif->tif_dir.td_stripbytecount != NULL )
3894  {
3896  "tif->tif_dir.td_stripbytecount is "
3897  "already allocated. Likely duplicated "
3898  "StripByteCounts/TileByteCounts tag");
3899  goto bad;
3900  }
3902  goto bad;
3903 #endif
3904  break;
3905  case TIFFTAG_COLORMAP:
3907  {
3908  enum TIFFReadDirEntryErr err;
3909  uint32 countpersample;
3910  uint32 countrequired;
3911  uint32 incrementpersample;
3912  uint16* value=NULL;
3913  /* It would be dangerous to instantiate those tag values */
3914  /* since if td_bitspersample has not yet been read (due to */
3915  /* unordered tags), it could be read afterwards with a */
3916  /* values greater than the default one (1), which may cause */
3917  /* crashes in user code */
3918  if( !bitspersample_read )
3919  {
3920  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3922  "Ignoring %s since BitsPerSample tag not found",
3923  fip ? fip->field_name : "unknown tagname");
3924  continue;
3925  }
3926  /* ColorMap or TransferFunction for high bit */
3927  /* depths do not make much sense and could be */
3928  /* used as a denial of service vector */
3929  if (tif->tif_dir.td_bitspersample > 24)
3930  {
3931  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3933  "Ignoring %s because BitsPerSample=%d>24",
3934  fip ? fip->field_name : "unknown tagname",
3935  tif->tif_dir.td_bitspersample);
3936  continue;
3937  }
3938  countpersample=(1U<<tif->tif_dir.td_bitspersample);
3939  if ((dp->tdir_tag==TIFFTAG_TRANSFERFUNCTION)&&(dp->tdir_count==(uint64)countpersample))
3940  {
3941  countrequired=countpersample;
3942  incrementpersample=0;
3943  }
3944  else
3945  {
3946  countrequired=3*countpersample;
3947  incrementpersample=countpersample;
3948  }
3949  if (dp->tdir_count!=(uint64)countrequired)
3951  else
3954  {
3955  fip = TIFFFieldWithTag(tif,dp->tdir_tag);
3956  TIFFReadDirEntryOutputErr(tif,err,module,fip ? fip->field_name : "unknown tagname",1);
3957  }
3958  else
3959  {
3960  TIFFSetField(tif,dp->tdir_tag,value,value+incrementpersample,value+2*incrementpersample);
3961  _TIFFfree(value);
3962  }
3963  }
3964  break;
3965 /* BEGIN REV 4.0 COMPATIBILITY */
3966  case TIFFTAG_OSUBFILETYPE:
3967  {
3968  uint16 valueo;
3969  uint32 value;
3970  if (TIFFReadDirEntryShort(tif,dp,&valueo)==TIFFReadDirEntryErrOk)
3971  {
3972  switch (valueo)
3973  {
3975  case OFILETYPE_PAGE: value=FILETYPE_PAGE; break;
3976  default: value=0; break;
3977  }
3978  if (value!=0)
3980  }
3981  }
3982  break;
3983 /* END REV 4.0 COMPATIBILITY */
3984  default:
3985  (void) TIFFFetchNormalTag(tif, dp, TRUE);
3986  break;
3987  }
3988  }
3989  /*
3990  * OJPEG hack:
3991  * - If a) compression is OJPEG, and b) photometric tag is missing,
3992  * then we consistently find that photometric should be YCbCr
3993  * - If a) compression is OJPEG, and b) photometric tag says it's RGB,
3994  * then we consistently find that the buggy implementation of the
3995  * buggy compression scheme matches photometric YCbCr instead.
3996  * - If a) compression is OJPEG, and b) bitspersample tag is missing,
3997  * then we consistently find bitspersample should be 8.
3998  * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
3999  * and c) photometric is RGB or YCbCr, then we consistently find
4000  * samplesperpixel should be 3
4001  * - If a) compression is OJPEG, b) samplesperpixel tag is missing,
4002  * and c) photometric is MINISWHITE or MINISBLACK, then we consistently
4003  * find samplesperpixel should be 3
4004  */
4006  {
4007  if (!TIFFFieldSet(tif,FIELD_PHOTOMETRIC))
4008  {
4010  "Photometric tag is missing, assuming data is YCbCr");
4012  goto bad;
4013  }
4014  else if (tif->tif_dir.td_photometric==PHOTOMETRIC_RGB)
4015  {
4018  "Photometric tag value assumed incorrect, "
4019  "assuming data is YCbCr instead of RGB");
4020  }
4022  {
4024  "BitsPerSample tag is missing, assuming 8 bits per sample");
4025  if (!TIFFSetField(tif,TIFFTAG_BITSPERSAMPLE,8))
4026  goto bad;
4027  }
4029  {
4031  {
4033  "SamplesPerPixel tag is missing, "
4034  "assuming correct SamplesPerPixel value is 3");
4036  goto bad;
4037  }
4039  {
4041  "SamplesPerPixel tag is missing, "
4042  "applying correct SamplesPerPixel value of 3");
4044  goto bad;
4045  }
4048  {
4049  /*
4050  * SamplesPerPixel tag is missing, but is not required
4051  * by spec. Assume correct SamplesPerPixel value of 1.
4052  */
4054  goto bad;
4055  }
4056  }
4057  }
4058 
4059  /*
4060  * Make sure all non-color channels are extrasamples.
4061  * If it's not the case, define them as such.
4062  */
4063  color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
4064  if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {
4065  uint16 old_extrasamples;
4066  uint16 *new_sampleinfo;
4067 
4068  TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "
4069  "color channels and ExtraSamples doesn't match SamplesPerPixel. "
4070  "Defining non-color channels as ExtraSamples.");
4071 
4072  old_extrasamples = tif->tif_dir.td_extrasamples;
4073  tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);
4074 
4075  // sampleinfo should contain information relative to these new extra samples
4076  new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
4077  if (!new_sampleinfo) {
4078  TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "
4079  "temporary new sampleinfo array (%d 16 bit elements)",
4080  tif->tif_dir.td_extrasamples);
4081  goto bad;
4082  }
4083 
4084  memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
4085  _TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
4086  _TIFFfree(new_sampleinfo);
4087  }
4088 
4089  /*
4090  * Verify Palette image has a Colormap.
4091  */
4093  !TIFFFieldSet(tif, FIELD_COLORMAP)) {
4094  if ( tif->tif_dir.td_bitspersample>=8 && tif->tif_dir.td_samplesperpixel==3)
4096  else if (tif->tif_dir.td_bitspersample>=8)
4098  else {
4099  MissingRequired(tif, "Colormap");
4100  goto bad;
4101  }
4102  }
4103  /*
4104  * OJPEG hack:
4105  * We do no further messing with strip/tile offsets/bytecounts in OJPEG
4106  * TIFFs
4107  */
4109  {
4110  /*
4111  * Attempt to deal with a missing StripByteCounts tag.
4112  */
4113  if (!TIFFFieldSet(tif, FIELD_STRIPBYTECOUNTS)) {
4114  /*
4115  * Some manufacturers violate the spec by not giving
4116  * the size of the strips. In this case, assume there
4117  * is one uncompressed strip of data.
4118  */
4120  tif->tif_dir.td_nstrips > 1) ||
4123  MissingRequired(tif, "StripByteCounts");
4124  goto bad;
4125  }
4127  "TIFF directory is missing required "
4128  "\"StripByteCounts\" field, calculating from imagelength");
4129  if (EstimateStripByteCounts(tif, dir, dircount) < 0)
4130  goto bad;
4131  /*
4132  * Assume we have wrong StripByteCount value (in case
4133  * of single strip) in following cases:
4134  * - it is equal to zero along with StripOffset;
4135  * - it is larger than file itself (in case of uncompressed
4136  * image);
4137  * - it is smaller than the size of the bytes per row
4138  * multiplied on the number of rows. The last case should
4139  * not be checked in the case of writing new image,
4140  * because we may do not know the exact strip size
4141  * until the whole image will be written and directory
4142  * dumped out.
4143  */
4144  #define BYTECOUNTLOOKSBAD \
4145  ( (tif->tif_dir.td_stripbytecount[0] == 0 && tif->tif_dir.td_stripoffset[0] != 0) || \
4146  (tif->tif_dir.td_compression == COMPRESSION_NONE && \
4147  (tif->tif_dir.td_stripoffset[0] <= TIFFGetFileSize(tif) && \
4148  tif->tif_dir.td_stripbytecount[0] > TIFFGetFileSize(tif) - tif->tif_dir.td_stripoffset[0])) || \
4149  (tif->tif_mode == O_RDONLY && \
4150  tif->tif_dir.td_compression == COMPRESSION_NONE && \
4151  tif->tif_dir.td_stripbytecount[0] < TIFFScanlineSize64(tif) * tif->tif_dir.td_imagelength) )
4152 
4153  } else if (tif->tif_dir.td_nstrips == 1
4154  && !(tif->tif_flags&TIFF_ISTILED)
4155  && _TIFFFillStriles(tif)
4156  && tif->tif_dir.td_stripoffset[0] != 0
4157  && BYTECOUNTLOOKSBAD) {
4158  /*
4159  * XXX: Plexus (and others) sometimes give a value of
4160  * zero for a tag when they don't know what the
4161  * correct value is! Try and handle the simple case
4162  * of estimating the size of a one strip image.
4163  */
4165  "Bogus \"StripByteCounts\" field, ignoring and calculating from imagelength");
4166  if(EstimateStripByteCounts(tif, dir, dircount) < 0)
4167  goto bad;
4168 
4169 #if !defined(DEFER_STRILE_LOAD)
4170  } else if (tif->tif_dir.td_planarconfig == PLANARCONFIG_CONTIG
4171  && tif->tif_dir.td_nstrips > 2
4173  && tif->tif_dir.td_stripbytecount[0] != tif->tif_dir.td_stripbytecount[1]
4174  && tif->tif_dir.td_stripbytecount[0] != 0
4175  && tif->tif_dir.td_stripbytecount[1] != 0 ) {
4176  /*
4177  * XXX: Some vendors fill StripByteCount array with
4178  * absolutely wrong values (it can be equal to
4179  * StripOffset array, for example). Catch this case
4180  * here.
4181  *
4182  * We avoid this check if deferring strile loading
4183  * as it would always force us to load the strip/tile
4184  * information.
4185  */
4187  "Wrong \"StripByteCounts\" field, ignoring and calculating from imagelength");
4188  if (EstimateStripByteCounts(tif, dir, dircount) < 0)
4189  goto bad;
4190 #endif /* !defined(DEFER_STRILE_LOAD) */
4191  }
4192  }
4193  if (dir)
4194  {
4195  _TIFFfree(dir);
4196  dir=NULL;
4197  }
4199  {
4200  if (tif->tif_dir.td_bitspersample>=16)
4201  tif->tif_dir.td_maxsamplevalue=0xFFFF;
4202  else
4204  }
4205  /*
4206  * XXX: We can optimize checking for the strip bounds using the sorted
4207  * bytecounts array. See also comments for TIFFAppendToStrip()
4208  * function in tif_write.c.
4209  */
4210 #if !defined(DEFER_STRILE_LOAD)
4211  if (tif->tif_dir.td_nstrips > 1) {
4212  uint32 strip;
4213 
4215  for (strip = 1; strip < tif->tif_dir.td_nstrips; strip++) {
4216  if (tif->tif_dir.td_stripoffset[strip - 1] >
4217  tif->tif_dir.td_stripoffset[strip]) {
4219  break;
4220  }
4221  }
4222  }
4223 #endif /* !defined(DEFER_STRILE_LOAD) */
4224 
4225  /*
4226  * An opportunity for compression mode dependent tag fixup
4227  */
4228  (*tif->tif_fixuptags)(tif);
4229 
4230  /*
4231  * Some manufacturers make life difficult by writing
4232  * large amounts of uncompressed data as a single strip.
4233  * This is contrary to the recommendations of the spec.
4234  * The following makes an attempt at breaking such images
4235  * into strips closer to the recommended 8k bytes. A
4236  * side effect, however, is that the RowsPerStrip tag
4237  * value may be changed.
4238  */
4240  (tif->tif_dir.td_nstrips==1)&&
4243  {
4244  if ( !_TIFFFillStriles(tif) || !tif->tif_dir.td_stripbytecount )
4245  return 0;
4247  }
4248 
4249  /*
4250  * Clear the dirty directory flag.
4251  */
4252  tif->tif_flags &= ~TIFF_DIRTYDIRECT;
4253  tif->tif_flags &= ~TIFF_DIRTYSTRIP;
4254 
4255  /*
4256  * Reinitialize i/o since we are starting on a new directory.
4257  */
4258  tif->tif_row = (uint32) -1;
4259  tif->tif_curstrip = (uint32) -1;
4260  tif->tif_col = (uint32) -1;
4261  tif->tif_curtile = (uint32) -1;
4262  tif->tif_tilesize = (tmsize_t) -1;
4263 
4264  tif->tif_scanlinesize = TIFFScanlineSize(tif);
4265  if (!tif->tif_scanlinesize) {
4267  "Cannot handle zero scanline size");
4268  return (0);
4269  }
4270 
4271  if (isTiled(tif)) {
4272  tif->tif_tilesize = TIFFTileSize(tif);
4273  if (!tif->tif_tilesize) {
4275  "Cannot handle zero tile size");
4276  return (0);
4277  }
4278  } else {
4279  if (!TIFFStripSize(tif)) {
4281  "Cannot handle zero strip size");
4282  return (0);
4283  }
4284  }
4285  return (1);
4286 bad:
4287  if (dir)
4288  _TIFFfree(dir);
4289  return (0);
4290 }
unsigned long long uint64
Definition: platform.h:18
#define TIFFTAG_SUBFILETYPE
Definition: tiff.h:146
#define TIFF_BEENWRITING
Definition: tiffiop.h:112
#define FIELD_IGNORE
Definition: tif_dir.h:134
#define TRUE
Definition: types.h:120
uint16 td_bitspersample
Definition: tif_dir.h:74
#define PHOTOMETRIC_YCBCR
Definition: tiff.h:202
static void TIFFReadDirectoryFindFieldInfo(TIFF *tif, uint16 tagid, uint32 *fii)
Definition: tif_dirread.c:4327
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:72
#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:55
uint32 TIFFNumberOfStrips(TIFF *tif)
Definition: tif_strip.c:60
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray(TIFF *tif, TIFFDirEntry *direntry, double **value)
Definition: tif_dirread.c:2527
static int _TIFFGetMaxColorChannels(uint16 photometric)
Definition: tif_dirread.c:3513
#define FIELD_STRIPOFFSETS
Definition: tif_dir.h:158
#define TIFFTAG_STRIPBYTECOUNTS
Definition: tiff.h:234
#define TIFFTAG_COLORMAP
Definition: tiff.h:284
#define TIFF_STRIPCHOP
Definition: tiffiop.h:121
#define TIFFTAG_EXTRASAMPLES
Definition: tiff.h:304
#define FIELD_IMAGEDIMENSIONS
Definition: tif_dir.h:137
unsigned int uint32
Definition: types.h:32
#define TIFF_ISTILED
Definition: tiffiop.h:116
#define TIFFTAG_IMAGEWIDTH
Definition: tiff.h:154
#define U(x)
Definition: wordpad.c:44
#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:145
static int TIFFFetchNormalTag(TIFF *, TIFFDirEntry *, int recover)
Definition: tif_dirread.c:4914
#define assert(x)
Definition: debug.h:53
uint32 td_imagedepth
Definition: tif_dir.h:71
#define TIFFTAG_STRIPOFFSETS
Definition: tiff.h:222
tmsize_t tif_scanlinesize
Definition: tiffiop.h:177
#define OFILETYPE_PAGE
Definition: tiff.h:153
#define COMPRESSION_OJPEG
Definition: tiff.h:165
thandle_t tif_clientdata
Definition: tiffiop.h:191
#define TIFFTAG_SMINSAMPLEVALUE
Definition: tiff.h:315
uint32 TIFFNumberOfTiles(TIFF *tif)
Definition: tif_tile.c:114
uint16 tif_curdir
Definition: tiffiop.h:144
#define TIFFTAG_PLANARCONFIG
Definition: tiff.h:239
tmsize_t tif_tilesize
Definition: tiffiop.h:154
#define IGNORE
Definition: tif_dirread.c:44
#define TIFF_DIRTYDIRECT
Definition: tiffiop.h:109
const GLfloat * m
Definition: glext.h:10848
#define TIFFTAG_TILEBYTECOUNTS
Definition: tiff.h:289
uint32 td_tilelength
Definition: tif_dir.h:72
unsigned short field_bit
Definition: tif_dir.h:286
tmsize_t TIFFStripSize(TIFF *tif)
Definition: tif_strip.c:211
#define PHOTOMETRIC_RGB
Definition: tiff.h:198
#define FIELD_MAXSAMPLEVALUE
Definition: tif_dir.h:153
#define FIELD_BITSPERSAMPLE
Definition: tif_dir.h:144
static void TIFFReadDirectoryCheckOrder(TIFF *tif, TIFFDirEntry *dir, uint16 dircount)
Definition: tif_dirread.c:4293
#define TIFFSetFieldBit(tif, field)
Definition: tif_dir.h:193
#define TIFFTAG_TILEWIDTH
Definition: tiff.h:286
char * field_name
Definition: tif_dir.h:289
#define FIELD_STRIPBYTECOUNTS
Definition: tif_dir.h:157
int td_stripbytecountsorted
Definition: tif_dir.h:102
uint16 * td_sampleinfo
Definition: tif_dir.h:94
TIFF_SSIZE_T tmsize_t
Definition: tiffio.h:65
static int TIFFFetchStripThing(TIFF *tif, TIFFDirEntry *dir, uint32 nstrips, uint64 **lpp)
Definition: tif_dirread.c:5599
int _TIFFMergeFields(TIFF *tif, const TIFFField info[], uint32 n)
Definition: tif_dirinfo.c:369
uint32 td_stripsperimage
Definition: tif_dir.h:98
#define TIFFTAG_TILELENGTH
Definition: tiff.h:287
#define FAILED_FII
Definition: tif_dirread.c:45
uint32 tif_flags
Definition: tiffiop.h:106
#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:88
unsigned int dir
Definition: maze.c:112
uint64 tif_nextdiroff
Definition: tiffiop.h:131
#define PHOTOMETRIC_PALETTE
Definition: tiff.h:199
void TIFFFreeDirectory(TIFF *tif)
Definition: tif_dir.c:1251
#define TIFF_BUF4WRITE
Definition: tiffiop.h:126
static void MissingRequired(TIFF *, const char *)
Definition: tif_dirread.c:4569
#define PHOTOMETRIC_MINISBLACK
Definition: tiff.h:197
uint32 td_nstrips
Definition: tif_dir.h:99
#define TIFF_PERSAMPLE
Definition: tiffiop.h:128
uint16 td_extrasamples
Definition: tif_dir.h:93
uint16 td_photometric
Definition: tif_dir.h:77
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:4478
#define FIELD_PHOTOMETRIC
Definition: tif_dir.h:146
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:192
uint64 * td_stripoffset
Definition: tif_dir.h:100
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:127
static const WCHAR L[]
Definition: oid.c:1250
#define TIFFTAG_TRANSFERFUNCTION
Definition: tiff.h:273
uint64 tif_diroff
Definition: tiffiop.h:130
uint32 tif_curtile
Definition: tiffiop.h:153
#define COMPRESSION_NONE
Definition: tiff.h:158
#define TIFFTAG_COMPRESSION
Definition: tiff.h:157
uint32 td_tilewidth
Definition: tif_dir.h:72
#define PLANARCONFIG_SEPARATE
Definition: tiff.h:241
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
uint64 * td_stripbytecount
Definition: tif_dir.h:101
#define FILETYPE_REDUCEDIMAGE
Definition: tiff.h:147
TIFFVoidMethod tif_cleanup
Definition: tiffiop.h:172
const TIFFField * TIFFFieldWithTag(TIFF *tif, uint32 tag)
Definition: tif_dirinfo.c:558
#define err(...)
#define isTiled(tif)
Definition: tiffiop.h:213
#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:5709
TIFFField ** tif_fields
Definition: tiffiop.h:200
uint16 td_maxsamplevalue
Definition: tif_dir.h:83
#define OFILETYPE_REDUCEDIMAGE
Definition: tiff.h:152
uint32 td_rowsperstrip
Definition: tif_dir.h:82
uint32 tif_row
Definition: tiffiop.h:143
#define TIFFTAG_TILEDEPTH
Definition: tiff.h:387
#define TIFFTAG_IMAGEDEPTH
Definition: tiff.h:386
#define BYTECOUNTLOOKSBAD
tmsize_t TIFFScanlineSize(TIFF *tif)
Definition: tif_strip.c:330
unsigned short uint16
Definition: types.h:30
TIFFBoolMethod tif_fixuptags
Definition: tiffiop.h:157
TIFFDirectory tif_dir
Definition: tiffiop.h:135
#define FIELD_TILEDIMENSIONS
Definition: tif_dir.h:138
static int TIFFCheckDirOffset(TIFF *tif, uint64 diroff)
Definition: tif_dirread.c:4585
tmsize_t TIFFTileSize(TIFF *tif)
Definition: tif_tile.c:272
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:289
static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:2825
int TIFFDefaultDirectory(TIFF *tif)
Definition: tif_dir.c:1356
void _TIFFsetShortArray(uint16 **wpp, uint16 *wp, uint32 n)
Definition: tif_dir.c:63
#define FIELD_COLORMAP
Definition: tif_dir.h:159
#define FIELD_SAMPLESPERPIXEL
Definition: tif_dir.h:150
static void TIFFReadDirEntryOutputErr(TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
Definition: tif_dirread.c:3421
uint16 td_samplesperpixel
Definition: tif_dir.h:81
static TIFFDirEntry * TIFFReadDirectoryFindEntry(TIFF *tif, TIFFDirEntry *dir, uint16 dircount, uint16 tagid)
Definition: tif_dirread.c:4313
uint16 td_compression
Definition: tif_dir.h:76
void _TIFFfree(void *p)
Definition: tif_unix.c:326
uint32 tif_col
Definition: tiffiop.h:152
#define TIFFTAG_SAMPLEFORMAT
Definition: tiff.h:308
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray(TIFF *tif, TIFFDirEntry *direntry, uint16 **value)
Definition: tif_dirread.c:1291
#define TIFFTAG_OSUBFILETYPE
Definition: tiff.h:150
static uint16 TIFFFetchDirectory(TIFF *tif, uint64 diroff, TIFFDirEntry **pdir, uint64 *nextdiroff)
Definition: tif_dirread.c:4659
uint32 td_imagewidth
Definition: tif_dir.h:71
int TIFFSetField(TIFF *tif, uint32 tag,...)
Definition: tif_dir.c:790
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:5812
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 4293 of file tif_dirread.c.

4294 {
4295  static const char module[] = "TIFFReadDirectoryCheckOrder";
4296  uint16 m;
4297  uint16 n;
4298  TIFFDirEntry* o;
4299  m=0;
4300  for (n=0, o=dir; n<dircount; n++, o++)
4301  {
4302  if (o->tdir_tag<m)
4303  {
4305  "Invalid TIFF directory; tags are not sorted in ascending order");
4306  break;
4307  }
4308  m=o->tdir_tag+1;
4309  }
4310 }
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:191
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 4313 of file tif_dirread.c.

4314 {
4315  TIFFDirEntry* m;
4316  uint16 n;
4317  (void) tif;
4318  for (m=dir, n=0; n<dircount; m++, n++)
4319  {
4320  if (m->tdir_tag==tagid)
4321  return(m);
4322  }
4323  return(0);
4324 }
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 4327 of file tif_dirread.c.

4328 {
4329  int32 ma,mb,mc;
4330  ma=-1;
4331  mc=(int32)tif->tif_nfields;
4332  while (1)
4333  {
4334  if (ma+1==mc)
4335  {
4336  *fii = FAILED_FII;
4337  return;
4338  }
4339  mb=(ma+mc)/2;
4340  if (tif->tif_fields[mb]->field_tag==(uint32)tagid)
4341  break;
4342  if (tif->tif_fields[mb]->field_tag<(uint32)tagid)
4343  ma=mb;
4344  else
4345  mc=mb;
4346  }
4347  while (1)
4348  {
4349  if (mb==0)
4350  break;
4351  if (tif->tif_fields[mb-1]->field_tag!=(uint32)tagid)
4352  break;
4353  mb--;
4354  }
4355  *fii=mb;
4356 }
unsigned int uint32
Definition: types.h:32
while(1)
Definition: macro.lex.yy.c:740
#define FAILED_FII
Definition: tif_dirread.c:45
size_t tif_nfields
Definition: tiffiop.h:201
uint32 field_tag
Definition: tif_dir.h:279
TIFFField ** tif_fields
Definition: tiffiop.h:200
long int32
Definition: platform.h:12

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

◆ TIFFReadDirEntryArray()

static enum TIFFReadDirEntryErr TIFFReadDirEntryArray ( TIFF tif,
TIFFDirEntry direntry,
uint32 count,
uint32  desttypesize,
void **  value 
)
static

Definition at line 925 of file tif_dirread.c.

926 {
927  return TIFFReadDirEntryArrayWithLimit(tif, direntry, count,
928  desttypesize, value, ~((uint64)0));
929 }
unsigned long long uint64
Definition: platform.h:18
static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit(TIFF *tif, TIFFDirEntry *direntry, uint32 *count, uint32 desttypesize, void **value, uint64 maxcount)
Definition: tif_dirread.c:830
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by TIFFReadDirEntryByteArray(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLongArray(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), and TIFFReadDirEntrySshortArray().

◆ TIFFReadDirEntryArrayWithLimit()

static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit ( TIFF tif,
TIFFDirEntry direntry,
uint32 count,
uint32  desttypesize,
void **  value,
uint64  maxcount 
)
static

Definition at line 830 of file tif_dirread.c.

833 {
834  int typesize;
836  void* data;
837  uint64 target_count64;
838  typesize=TIFFDataWidth(direntry->tdir_type);
839 
840  target_count64 = (direntry->tdir_count > maxcount) ?
841  maxcount : direntry->tdir_count;
842 
843  if ((target_count64==0)||(typesize==0))
844  {
845  *value=0;
846  return(TIFFReadDirEntryErrOk);
847  }
848  (void) desttypesize;
849 
850  /*
851  * As a sanity check, make sure we have no more than a 2GB tag array
852  * in either the current data type or the dest data type. This also
853  * avoids problems with overflow of tmsize_t on 32bit systems.
854  */
855  if ((uint64)(2147483647/typesize)<target_count64)
857  if ((uint64)(2147483647/desttypesize)<target_count64)
859 
860  *count=(uint32)target_count64;
861  datasize=(*count)*typesize;
863 
864  if( isMapped(tif) && datasize > (uint32)tif->tif_size )
865  return TIFFReadDirEntryErrIo;
866 
867  if( !isMapped(tif) &&
868  (((tif->tif_flags&TIFF_BIGTIFF) && datasize > 8) ||
869  (!(tif->tif_flags&TIFF_BIGTIFF) && datasize > 4)) )
870  {
871  data = NULL;
872  }
873  else
874  {
875  data=_TIFFCheckMalloc(tif, *count, typesize, "ReadDirEntryArray");
876  if (data==0)
877  return(TIFFReadDirEntryErrAlloc);
878  }
879  if (!(tif->tif_flags&TIFF_BIGTIFF))
880  {
881  if (datasize<=4)
882  _TIFFmemcpy(data,&direntry->tdir_offset,datasize);
883  else
884  {
886  uint32 offset = direntry->tdir_offset.toff_long;
887  if (tif->tif_flags&TIFF_SWAB)
889  if( isMapped(tif) )
891  else
894  {
895  _TIFFfree(data);
896  return(err);
897  }
898  }
899  }
900  else
901  {
902  if (datasize<=8)
903  _TIFFmemcpy(data,&direntry->tdir_offset,datasize);
904  else
905  {
907  uint64 offset = direntry->tdir_offset.toff_long8;
908  if (tif->tif_flags&TIFF_SWAB)
910  if( isMapped(tif) )
912  else
915  {
916  _TIFFfree(data);
917  return(err);
918  }
919  }
920  }
921  *value=data;
922  return(TIFFReadDirEntryErrOk);
923 }
unsigned long long uint64
Definition: platform.h:18
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
static SIZE_T datasize
Definition: asm.c:30
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int uint32
Definition: types.h:32
GLintptr offset
Definition: glext.h:5920
#define assert(x)
Definition: debug.h:53
union TIFFDirEntry::@3328 tdir_offset
static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(TIFF *tif, uint64 offset, tmsize_t size, void **pdest)
Definition: tif_dirread.c:775
#define TIFF_BIGTIFF
Definition: tiffiop.h:125
#define TIFF_SWAB
Definition: tiffiop.h:113
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:85
uint32 tif_flags
Definition: tiffiop.h:106
smooth NULL
Definition: ftsmooth.c:416
#define isMapped(tif)
Definition: tiffiop.h:214
if(!(yy_init))
Definition: macro.lex.yy.c:714
uint32 toff_long
Definition: tif_dir.h:58
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 TIFFReadDirEntryData(TIFF *tif, uint64 offset, tmsize_t size, void *dest)
Definition: tif_dirread.c:3397
tmsize_t tif_size
Definition: tiffiop.h:187
#define err(...)
int TIFFDataWidth(TIFFDataType type)
Definition: tif_dirinfo.c:438
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
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

Referenced by TIFFReadDirEntryArray(), and TIFFReadDirEntryLong8ArrayWithLimit().

◆ TIFFReadDirEntryByte()

static enum TIFFReadDirEntryErr TIFFReadDirEntryByte ( TIFF tif,
TIFFDirEntry direntry,
uint8 value 
)
static

Definition at line 200 of file tif_dirread.c.

201 {
203  if (direntry->tdir_count!=1)
204  return(TIFFReadDirEntryErrCount);
205  switch (direntry->tdir_type)
206  {
207  case TIFF_BYTE:
208  TIFFReadDirEntryCheckedByte(tif,direntry,value);
209  return(TIFFReadDirEntryErrOk);
210  case TIFF_SBYTE:
211  {
212  int8 m;
213  TIFFReadDirEntryCheckedSbyte(tif,direntry,&m);
216  return(err);
217  *value=(uint8)m;
218  return(TIFFReadDirEntryErrOk);
219  }
220  case TIFF_SHORT:
221  {
222  uint16 m;
223  TIFFReadDirEntryCheckedShort(tif,direntry,&m);
226  return(err);
227  *value=(uint8)m;
228  return(TIFFReadDirEntryErrOk);
229  }
230  case TIFF_SSHORT:
231  {
232  int16 m;
233  TIFFReadDirEntryCheckedSshort(tif,direntry,&m);
236  return(err);
237  *value=(uint8)m;
238  return(TIFFReadDirEntryErrOk);
239  }
240  case TIFF_LONG:
241  {
242  uint32 m;
243  TIFFReadDirEntryCheckedLong(tif,direntry,&m);
246  return(err);
247  *value=(uint8)m;
248  return(TIFFReadDirEntryErrOk);
249  }
250  case TIFF_SLONG:
251  {
252  int32 m;
253  TIFFReadDirEntryCheckedSlong(tif,direntry,&m);
256  return(err);
257  *value=(uint8)m;
258  return(TIFFReadDirEntryErrOk);
259  }
260  case TIFF_LONG8:
261  {
262  uint64 m;
263  err=TIFFReadDirEntryCheckedLong8(tif,direntry,&m);
265  return(err);
268  return(err);
269  *value=(uint8)m;
270  return(TIFFReadDirEntryErrOk);
271  }
272  case TIFF_SLONG8:
273  {
274  int64 m;
275  err=TIFFReadDirEntryCheckedSlong8(tif,direntry,&m);
277  return(err);
280  return(err);
281  *value=(uint8)m;
282  return(TIFFReadDirEntryErrOk);
283  }
284  default:
285  return(TIFFReadDirEntryErrType);
286  }
287 }
unsigned long long uint64
Definition: platform.h:18
static void TIFFReadDirEntryCheckedSshort(TIFF *tif, TIFFDirEntry *direntry, int16 *value)
Definition: tif_dirread.c:2903
static void TIFFReadDirEntryCheckedByte(TIFF *tif, TIFFDirEntry *direntry, uint8 *value)
Definition: tif_dirread.c:2883
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value)
Definition: tif_dirread.c:3066
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value)
Definition: tif_dirread.c:3098
unsigned int uint32
Definition: types.h:32
long long int64
Definition: platform.h:13
const GLfloat * m
Definition: glext.h:10848
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value)
Definition: tif_dirread.c:3106
static void TIFFReadDirEntryCheckedLong(TIFF *tif, TIFFDirEntry *direntry, uint32 *value)
Definition: tif_dirread.c:2910
static void TIFFReadDirEntryCheckedSbyte(TIFF *tif, TIFFDirEntry *direntry, int8 *value)
Definition: tif_dirread.c:2889
unsigned char uint8
Definition: types.h:28
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value)
Definition: tif_dirread.c:3074
uint64 tdir_count
Definition: tif_dir.h:55
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8(TIFF *tif, TIFFDirEntry *direntry, uint64 *value)
Definition: tif_dirread.c:2924
#define err(...)
unsigned short uint16
Definition: types.h:30
short int16
Definition: platform.h:11
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value)
Definition: tif_dirread.c:3114
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value)
Definition: tif_dirread.c:3082
long int32
Definition: platform.h:12
static void TIFFReadDirEntryCheckedSlong(TIFF *tif, TIFFDirEntry *direntry, int32 *value)
Definition: tif_dirread.c:2917
static void TIFFReadDirEntryCheckedShort(TIFF *tif, TIFFDirEntry *direntry, uint16 *value)
Definition: tif_dirread.c:2895
char int8
Definition: platform.h:10
uint16 tdir_type
Definition: tif_dir.h:54
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value)
Definition: tif_dirread.c:3090
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8(TIFF *tif, TIFFDirEntry *direntry, int64 *value)
Definition: tif_dirread.c:2943

Referenced by TIFFFetchNormalTag().

◆ TIFFReadDirEntryByteArray()

static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray ( TIFF tif,
TIFFDirEntry direntry,
uint8 **  value 
)
static

Definition at line 931 of file tif_dirread.c.

932 {
934  uint32 count;
935  void* origdata;
936  uint8* data;
937  switch (direntry->tdir_type)
938  {
939  case TIFF_ASCII:
940  case TIFF_UNDEFINED:
941  case TIFF_BYTE:
942  case TIFF_SBYTE:
943  case TIFF_SHORT:
944  case TIFF_SSHORT:
945  case TIFF_LONG:
946  case TIFF_SLONG:
947  case TIFF_LONG8:
948  case TIFF_SLONG8:
949  break;
950  default:
951  return(TIFFReadDirEntryErrType);
952  }
953  err=TIFFReadDirEntryArray(tif,direntry,&count,1,&origdata);
954  if ((err!=TIFFReadDirEntryErrOk)||(origdata==0))
955  {
956  *value=0;
957  return(err);
958  }
959  switch (direntry->tdir_type)
960  {
961  case TIFF_ASCII:
962  case TIFF_UNDEFINED:
963  case TIFF_BYTE:
964  *value=(uint8*)origdata;
965  return(TIFFReadDirEntryErrOk);
966  case TIFF_SBYTE:
967  {
968  int8* m;
969  uint32 n;
970  m=(int8*)origdata;
971  for (n=0; n<count; n++)
972  {
975  {
976  _TIFFfree(origdata);
977  return(err);
978  }
979  m++;
980  }
981  *value=(uint8*)origdata;
982  return(TIFFReadDirEntryErrOk);
983  }
984  }
986  if (data==0)
987  {
988  _TIFFfree(origdata);
989  return(TIFFReadDirEntryErrAlloc);
990  }
991  switch (direntry->tdir_type)
992  {
993  case TIFF_SHORT:
994  {
995  uint16* ma;
996  uint8* mb;
997  uint32 n;
998  ma=(uint16*)origdata;
999  mb=data;
1000  for (n=0; n<count; n++)
1001  {
1002  if (tif->tif_flags&TIFF_SWAB)
1003  TIFFSwabShort(ma);
1006  break;
1007  *mb++=(uint8)(*ma++);
1008  }
1009  }
1010  break;
1011  case TIFF_SSHORT:
1012  {
1013  int16* ma;
1014  uint8* mb;
1015  uint32 n;
1016  ma=(int16*)origdata;
1017  mb=data;
1018  for (n=0; n<count; n++)
1019  {
1020  if (tif->tif_flags&TIFF_SWAB)
1021  TIFFSwabShort((uint16*)ma);
1024  break;
1025  *mb++=(uint8)(*ma++);
1026  }
1027  }
1028  break;
1029  case TIFF_LONG:
1030  {
1031  uint32* ma;
1032  uint8* mb;
1033  uint32 n;
1034  ma=(uint32*)origdata;
1035  mb=data;
1036  for (n=0; n<count; n++)
1037  {
1038  if (tif->tif_flags&TIFF_SWAB)
1039  TIFFSwabLong(ma);
1042  break;
1043  *mb++=(uint8)(*ma++);
1044  }
1045  }
1046  break;
1047  case TIFF_SLONG:
1048  {
1049  int32* ma;
1050  uint8* mb;
1051  uint32 n;
1052  ma=(int32*)origdata;
1053  mb=data;
1054  for (n=0; n<count; n++)
1055  {
1056  if (tif->tif_flags&TIFF_SWAB)
1057  TIFFSwabLong((uint32*)ma);
1060  break;
1061  *mb++=(uint8)(*ma++);
1062  }
1063  }
1064  break;
1065  case TIFF_LONG8:
1066  {
1067  uint64* ma;
1068  uint8* mb;
1069  uint32 n;
1070  ma=(uint64*)origdata;
1071  mb=data;
1072  for (n=0; n<count; n++)
1073  {
1074  if (tif->tif_flags&TIFF_SWAB)
1075  TIFFSwabLong8(ma);
1078  break;
1079  *mb++=(uint8)(*ma++);
1080  }
1081  }
1082  break;
1083  case TIFF_SLONG8:
1084  {
1085  int64* ma;
1086  uint8* mb;
1087  uint32 n;
1088  ma=(int64*)origdata;
1089  mb=data;
1090  for (n=0; n<count; n++)
1091  {
1092  if (tif->tif_flags&TIFF_SWAB)
1093  TIFFSwabLong8((uint64*)ma);
1096  break;
1097  *mb++=(uint8)(*ma++);
1098  }
1099  }
1100  break;
1101  }
1102  _TIFFfree(origdata);
1104  {
1105  _TIFFfree(data);
1106  return(err);
1107  }
1108  *value=data;
1109  return(TIFFReadDirEntryErrOk);
1110 }
unsigned long long uint64
Definition: platform.h:18
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte(int8 value)
Definition: tif_dirread.c:3066
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong(int32 value)
Definition: tif_dirread.c:3098
GLuint GLuint GLsizei count
Definition: gl.h:1545
unsigned int uint32
Definition: types.h:32
GLdouble n
Definition: glext.h:7729
long long int64
Definition: platform.h:13
const GLfloat * m
Definition: glext.h:10848
#define TIFF_SWAB
Definition: tiffiop.h:113
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8(uint64 value)
Definition: tif_dirread.c:3106
uint32 tif_flags
Definition: tiffiop.h:106
void * _TIFFmalloc(tmsize_t s)
Definition: tif_unix.c:309
void TIFFSwabShort(uint16 *wp)
Definition: tif_swab.c:34
unsigned char uint8
Definition: types.h:28
static enum TIFFReadDirEntryErr TIFFReadDirEntryArray(TIFF *tif, TIFFDirEntry *direntry, uint32 *count, uint32 desttypesize, void **value)
Definition: tif_dirread.c:925
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort(uint16 value)
Definition: tif_dirread.c:3074
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define err(...)
void TIFFSwabLong(uint32 *lp)
Definition: tif_swab.c:45
unsigned short uint16
Definition: types.h:30
short int16
Definition: platform.h:11
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8(int64 value)
Definition: tif_dirread.c:3114
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort(int16 value)
Definition: tif_dirread.c:3082
long int32
Definition: platform.h:12
void _TIFFfree(void *p)
Definition: tif_unix.c:326
void TIFFSwabLong8(uint64 *lp)
Definition: tif_swab.c:57
char int8
Definition: platform.h:10
uint16 tdir_type
Definition: tif_dir.h:54
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong(uint32 value)
Definition: tif_dirread.c:3090

Referenced by TIFFFetchNormalTag().

◆ TIFFReadDirEntryCheckedByte()

static void TIFFReadDirEntryCheckedByte ( TIFF tif,
TIFFDirEntry direntry,
uint8 value 
)
static

Definition at line 2883 of file tif_dirread.c.

2884 {
2885  (void) tif;
2886  *value=*(uint8*)(&direntry->tdir_offset);
2887 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
union TIFFDirEntry::@3328 tdir_offset
unsigned char uint8
Definition: types.h:28

Referenced by TIFFReadDirEntryByte(), TIFFReadDirEntryDouble(), TIFFReadDirEntryFloat(), TIFFReadDirEntryLong(), TIFFReadDirEntryLong8(), and TIFFReadDirEntryShort().

◆ TIFFReadDirEntryCheckedDouble()

static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble ( TIFF tif,
TIFFDirEntry direntry,
double value 
)
static

Definition at line 3040 of file tif_dirread.c.

3041 {
3042  assert(sizeof(double)==8);
3043  assert(sizeof(uint64)==8);
3044  assert(sizeof(UInt64Aligned_t)==8);
3045  if (!(tif->tif_flags&TIFF_BIGTIFF))
3046  {
3047  enum TIFFReadDirEntryErr err;
3048  uint32 offset = direntry->tdir_offset.toff_long;
3049  if (tif->tif_flags&TIFF_SWAB)
3050  TIFFSwabLong(&offset);
3053  return(err);
3054  }
3055  else
3056  {
3057  UInt64Aligned_t uint64_union;
3058  uint64_union.l=direntry->tdir_offset.toff_long8;
3059  *value=uint64_union.d;
3060  }
3061  if (tif->tif_flags&TIFF_SWAB)
3063  return(TIFFReadDirEntryErrOk);
3064 }
unsigned long long uint64
Definition: platform.h:18
TIFFReadDirEntryErr
Definition: tif_dirread.c:55
unsigned int uint32
Definition: types.h:32