LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
tif_dirread.c File Reference

Read directory entries and manage directory-chain maps. More...

#include "tiffconf.h"
#include "tiffiop.h"
#include <float.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for tif_dirread.c:

Go to the source code of this file.

Data Structures

union  _UInt64Aligned_t
 Provide aligned scalar and byte views of eight raw bytes. More...
 

Macros

#define FAILED_FII   ((uint32_t)-1)
 Represent a missing field-table index with UINT32_MAX.
 
#define TIFFCvtIEEEFloatToNative(tif, n, fp)
 Recognise already compatible float storage without conversion.
 
#define TIFFCvtIEEEDoubleToNative(tif, n, dp)
 Recognise already compatible double storage without conversion.
 
#define INITIAL_THRESHOLD   (1024 * 1024)
 Start progressive external-tag reads at one MiB on 64-bit hosts.
 
#define THRESHOLD_MULTIPLIER   10
 Grow progressive read requests by a factor of ten.
 
#define MAX_THRESHOLD
 Set the progressive read threshold cutoff to 1000 MiB.
 
#define MAX_SIZE_TAG_DATA   2147483647U
 Limit source and converted tag arrays to INT32_MAX bytes.
 
#define IO_CACHE_PAGE_SIZE   4096
 Set the lazy strile metadata read page size to 4096 bytes.
 
#define TIFF_MAX(a, b)   (((a) > (b)) ? (a) : (b))
 Select the larger of two expressions.
 
#define TIFF_MIN(a, b)   (((a) < (b)) ? (a) : (b))
 Select the smaller of two expressions.
 

Typedefs

typedef union _UInt64Aligned_t UInt64Aligned_t
 Provide aligned scalar and byte views of eight raw bytes.
 

Functions

static enum TIFFReadDirEntryErr TIFFReadDirEntryByte (TIFF *tif, TIFFDirEntry *direntry, uint8_t *value)
 Convert one directory value to uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyte (TIFF *tif, TIFFDirEntry *direntry, int8_t *value)
 Convert one directory value to int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryShort (TIFF *tif, TIFFDirEntry *direntry, uint16_t *value)
 Convert one directory value to uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySshort (TIFF *tif, TIFFDirEntry *direntry, int16_t *value)
 Convert one directory value to int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong (TIFF *tif, TIFFDirEntry *direntry, uint32_t *value)
 Convert one directory value to uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong (TIFF *tif, TIFFDirEntry *direntry, int32_t *value)
 Convert one directory value to int32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8 (TIFF *tif, TIFFDirEntry *direntry, uint64_t *value)
 Convert one directory value to uint64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8 (TIFF *tif, TIFFDirEntry *direntry, int64_t *value)
 Convert one directory value to int64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloat (TIFF *tif, TIFFDirEntry *direntry, float *value)
 Convert one directory value to float.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDouble (TIFF *tif, TIFFDirEntry *direntry, double *value)
 Convert one directory value to double.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8 (TIFF *tif, TIFFDirEntry *direntry, uint64_t *value)
 Convert one directory value to uint64_t directory offset.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryArray (TIFF *tif, TIFFDirEntry *direntry, uint32_t *count, uint32_t desttypesize, void **value)
 Fetch raw directory array bytes with checked size limits.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryByteArray (TIFF *tif, TIFFDirEntry *direntry, uint8_t **value)
 Read a directory array as uint8_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySbyteArray (TIFF *tif, TIFFDirEntry *direntry, int8_t **value)
 Read a directory array as int8_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryShortArray (TIFF *tif, TIFFDirEntry *direntry, uint16_t **value)
 Read a directory array as uint16_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySshortArray (TIFF *tif, TIFFDirEntry *direntry, int16_t **value)
 Read a directory array as int16_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLongArray (TIFF *tif, TIFFDirEntry *direntry, uint32_t **value)
 Read a directory array as uint32_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlongArray (TIFF *tif, TIFFDirEntry *direntry, int32_t **value)
 Read a directory array as int32_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8Array (TIFF *tif, TIFFDirEntry *direntry, uint64_t **value)
 Read a directory array as uint64_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntrySlong8Array (TIFF *tif, TIFFDirEntry *direntry, int64_t **value)
 Read a directory array as int64_t elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryFloatArray (TIFF *tif, TIFFDirEntry *direntry, float **value)
 Read a directory array as float elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDoubleArray (TIFF *tif, TIFFDirEntry *direntry, double **value)
 Read a directory array as double elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8Array (TIFF *tif, TIFFDirEntry *direntry, uint64_t **value)
 Read a directory array as uint64_t directory offset elements.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryPersampleShort (TIFF *tif, TIFFDirEntry *direntry, uint16_t *value)
 Reduce equal per-sample short values to one scalar.
 
static void TIFFReadDirEntryCheckedByte (TIFF *tif, TIFFDirEntry *direntry, uint8_t *value)
 Read a prevalidated uint8_t value.
 
static void TIFFReadDirEntryCheckedSbyte (TIFF *tif, TIFFDirEntry *direntry, int8_t *value)
 Read a prevalidated int8_t value.
 
static void TIFFReadDirEntryCheckedShort (TIFF *tif, TIFFDirEntry *direntry, uint16_t *value)
 Read a prevalidated uint16_t value.
 
static void TIFFReadDirEntryCheckedSshort (TIFF *tif, TIFFDirEntry *direntry, int16_t *value)
 Read a prevalidated int16_t value.
 
static void TIFFReadDirEntryCheckedLong (TIFF *tif, TIFFDirEntry *direntry, uint32_t *value)
 Read a prevalidated uint32_t value.
 
static void TIFFReadDirEntryCheckedSlong (TIFF *tif, TIFFDirEntry *direntry, int32_t *value)
 Read a prevalidated int32_t value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedLong8 (TIFF *tif, TIFFDirEntry *direntry, uint64_t *value)
 Read a prevalidated uint64_t value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSlong8 (TIFF *tif, TIFFDirEntry *direntry, int64_t *value)
 Read a prevalidated int64_t value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational (TIFF *tif, TIFFDirEntry *direntry, double *value)
 Read a prevalidated srational value.
 
static void TIFFReadDirEntryCheckedFloat (TIFF *tif, TIFFDirEntry *direntry, float *value)
 Read a prevalidated float value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedDouble (TIFF *tif, TIFFDirEntry *direntry, double *value)
 Read a prevalidated double value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSbyte (int8_t value)
 Check whether int8_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteShort (uint16_t value)
 Check whether uint16_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSshort (int16_t value)
 Check whether int16_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong (uint32_t value)
 Check whether uint32_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong (int32_t value)
 Check whether int32_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteLong8 (uint64_t value)
 Check whether uint64_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeByteSlong8 (int64_t value)
 Check whether int64_t fits uint8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteByte (uint8_t value)
 Check whether uint8_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteShort (uint16_t value)
 Check whether uint16_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSshort (int16_t value)
 Check whether int16_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong (uint32_t value)
 Check whether uint32_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong (int32_t value)
 Check whether int32_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteLong8 (uint64_t value)
 Check whether uint64_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSbyteSlong8 (int64_t value)
 Check whether int64_t fits int8_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSbyte (int8_t value)
 Check whether int8_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSshort (int16_t value)
 Check whether int16_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong (uint32_t value)
 Check whether uint32_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong (int32_t value)
 Check whether int32_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortLong8 (uint64_t value)
 Check whether uint64_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeShortSlong8 (int64_t value)
 Check whether int64_t fits uint16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortShort (uint16_t value)
 Check whether uint16_t fits int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong (uint32_t value)
 Check whether uint32_t fits int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong (int32_t value)
 Check whether int32_t fits int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortLong8 (uint64_t value)
 Check whether uint64_t fits int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSshortSlong8 (int64_t value)
 Check whether int64_t fits int16_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSbyte (int8_t value)
 Check whether int8_t fits uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSshort (int16_t value)
 Check whether int16_t fits uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong (int32_t value)
 Check whether int32_t fits uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongLong8 (uint64_t value)
 Check whether uint64_t fits uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong8 (int64_t value)
 Check whether int64_t fits uint32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong (uint32_t value)
 Check whether uint32_t fits int32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong8 (uint64_t value)
 Check whether uint64_t fits int32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongSlong8 (int64_t value)
 Check whether int64_t fits int32_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sbyte (int8_t value)
 Check whether int8_t fits uint64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Sshort (int16_t value)
 Check whether int16_t fits uint64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong (int32_t value)
 Check whether int32_t fits uint64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLong8Slong8 (int64_t value)
 Check whether int64_t fits uint64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlong8Long8 (uint64_t value)
 Check whether uint64_t fits int64_t.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryData (TIFF *tif, uint64_t offset, tmsize_t size, void *dest)
 Copy a raw external byte range into caller storage.
 
static void TIFFReadDirEntryOutputErr (TIFF *tif, enum TIFFReadDirEntryErr err, const char *module, const char *tagname, int recover)
 Report a directory-entry conversion error at the requested severity.
 
static void TIFFReadDirectoryCheckOrder (TIFF *tif, TIFFDirEntry *dir, uint16_t dircount)
 Warn if directory tags are not strictly increasing.
 
static TIFFDirEntry * TIFFReadDirectoryFindEntry (TIFF *tif, TIFFDirEntry *dir, uint16_t dircount, uint16_t tagid)
 Find the first parsed entry with a given tag.
 
static void TIFFReadDirectoryFindFieldInfo (TIFF *tif, uint16_t tagid, uint32_t *fii)
 Locate the first registered descriptor index for a tag.
 
static int EstimateStripByteCounts (TIFF *tif, TIFFDirEntry *dir, uint16_t dircount)
 Replace missing or suspect strile byte counts with estimates.
 
static void MissingRequired (TIFF *tif, const char *tagname)
 Report an absent required image tag.
 
static int CheckDirCount (TIFF *tif, TIFFDirEntry *dir, uint32_t count)
 Validate or trim an entry to its expected count.
 
static uint16_t TIFFFetchDirectory (TIFF *tif, uint64_t diroff, TIFFDirEntry **pdir, uint64_t *nextdiroff)
 Fetch and normalise raw classic TIFF or BigTIFF entries.
 
static int TIFFFetchNormalTag (TIFF *tif, TIFFDirEntry *dp, int recover)
 Decode a parsed value according to its registered set/get representation.
 
static int TIFFFetchStripThing (TIFF *tif, TIFFDirEntry *dir, uint32_t nstrips, uint64_t **lpp)
 Read a strile array and pad permitted missing elements with zero.
 
static int TIFFFetchSubjectDistance (TIFF *tif, TIFFDirEntry *dir)
 Decode EXIF SubjectDistance with its special sentinel values.
 
static void ChopUpSingleUncompressedStrip (TIFF *tif)
 Try to subdivide one contiguous uncompressed strip.
 
static void TryChopUpUncompressedBigTiff (TIFF *tif)
 Try to subdivide huge contiguous uncompressed strip data.
 
static uint64_t TIFFReadUInt64 (const uint8_t *value)
 Copy eight unaligned bytes into a native uint64_t value.
 
static int _TIFFGetMaxColorChannels (uint16_t photometric)
 Classify the expected maximum colour-channel count.
 
static int _TIFFFillStrilesInternal (TIFF *tif, int loadStripByteCount)
 Materialise deferred strile arrays or recognise an already-loaded state.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc (TIFF *tif, uint64_t offset, tmsize_t size, void **pdest)
 Grow an owned buffer while reading an external value.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit (TIFF *tif, TIFFDirEntry *direntry, uint32_t *count, uint32_t desttypesize, void **value, uint64_t maxcount)
 Fetch raw directory array bytes with checked size limits.
 
static enum TIFFReadDirEntryErr TIFFReadDirEntryLong8ArrayWithLimit (TIFF *tif, TIFFDirEntry *direntry, uint64_t **value, uint64_t maxcount)
 Read a directory array as uint64_t elements.
 
enum TIFFReadDirEntryErr _TIFFReadDirEntryCheckedRational (TIFF *tif, TIFFDirEntry *direntry, double *value)
 Read a prevalidated rational value.
 
static int ByteCountLooksBad (TIFF *tif)
 Test whether the first strip byte count needs recovery.
 
static bool EvaluateIFDdatasizeReading (TIFF *tif, TIFFDirEntry *dp)
 Record the external byte range of one IFD entry.
 
static int cmpTIFFEntryOffsetAndLength (const void *a, const void *b)
 Order external IFD ranges by starting byte offset.
 
static void CalcFinalIFDdatasizeReading (TIFF *tif, uint16_t dircount)
 Estimate the reusable contiguous span of the loaded IFD.
 
int TIFFReadDirectory (TIFF *tif)
 Read and install the next image directory.
 
int TIFFReadCustomDirectory (TIFF *tif, toff_t diroff, const TIFFFieldArray *infoarray)
 Read metadata using an explicit custom field schema.
 
int TIFFReadEXIFDirectory (TIFF *tif, toff_t diroff)
 Read a EXIF metadata directory.
 
int TIFFReadGPSDirectory (TIFF *tif, toff_t diroff)
 Read a EXIF GPS metadata directory.
 
static unsigned long hashFuncOffsetToNumber (const void *elt)
 Hash a directory-map offset key.
 
static bool equalFuncOffsetToNumber (const void *elt1, const void *elt2)
 Compare directory-map records by offset.
 
static unsigned long hashFuncNumberToOffset (const void *elt)
 Hash a directory-map directory index key.
 
static bool equalFuncNumberToOffset (const void *elt1, const void *elt2)
 Compare directory-map records by directory index.
 
static bool insertOffsetAndDirNumber (TIFF *tif, TIFFOffsetAndDirNumber *entryPtr)
 Add a directory-tracking record to both directory maps.
 
int _TIFFCheckDirNumberAndOffset (TIFF *tif, tdir_t dirn, uint64_t diroff)
 Register or validate a chain index/offset pair for loop detection.
 
int _TIFFGetDirNumberFromOffset (TIFF *tif, uint64_t diroff, tdir_t *dirn)
 Resolve a directory offset using the chain maps.
 
int _TIFFGetOffsetFromDirNumber (TIFF *tif, tdir_t dirn, uint64_t *diroff)
 Resolve an index from the existing number-to-offset map.
 
int _TIFFRemoveEntryFromDirectoryListByOffset (TIFF *tif, uint64_t diroff)
 Attempt to remove a shared directory-map entry by offset.
 
static void allocChoppedUpStripArrays (TIFF *tif, uint32_t nstrips, uint64_t stripbytes, uint32_t rowsperstrip)
 Replace uncompressed strip metadata with a logical subdivision.
 
static TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW uint64_t _TIFFUnsanitizedAddUInt64AndInt (uint64_t a, int b)
 Add a signed displacement with intentional unsigned wrap.
 
static int _TIFFPartialReadStripArray (TIFF *tif, TIFFDirEntry *dirent, int strile, uint64_t *panVals)
 Load a strile value and neighbouring page entries into a cache.
 
static int _TIFFFetchStrileValue (TIFF *tif, uint32_t strile, TIFFDirEntry *dirent, uint64_t **parray)
 Grow paired strile caches and fetch an uncached value.
 
static uint64_t _TIFFGetStrileOffsetOrByteCountValue (TIFF *tif, uint32_t strile, TIFFDirEntry *dirent, uint64_t **parray, int *pbErr)
 Resolve a cached, fully deferred, or lazy strile metadata value.
 
uint64_t TIFFGetStrileOffset (TIFF *tif, uint32_t strile)
 Query one logical strile file offset.
 
uint64_t TIFFGetStrileOffsetWithErr (TIFF *tif, uint32_t strile, int *pbErr)
 Query one logical strile file offset.
 
uint64_t TIFFGetStrileByteCount (TIFF *tif, uint32_t strile)
 Query one logical strile byte count.
 
uint64_t TIFFGetStrileByteCountWithErr (TIFF *tif, uint32_t strile, int *pbErr)
 Query one logical strile byte count.
 
int _TIFFFillStriles (TIFF *tif)
 Materialise deferred strile arrays when required.
 

Detailed Description

Read directory entries and manage directory-chain maps.

Definition in file tif_dirread.c.