|
LibTIFF 4.7.2
TIFF library public API and implementation reference
|
Load deferred/lazy arrays and construct logical uncompressed strips. More...
Macros | |
| #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. | |
Functions | |
| int | _TIFFFillStriles (TIFF *tif) |
| Materialise deferred strile arrays when required. | |
| 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 void | allocChoppedUpStripArrays (TIFF *tif, uint32_t nstrips, uint64_t stripbytes, uint32_t rowsperstrip) |
| Replace uncompressed strip metadata with a logical subdivision. | |
| 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 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. | |
| static int | _TIFFFillStrilesInternal (TIFF *tif, int loadStripByteCount) |
| Materialise deferred strile arrays or recognise an already-loaded state. | |
Load deferred/lazy arrays and construct logical uncompressed strips.
| #define IO_CACHE_PAGE_SIZE 4096 |
Set the lazy strile metadata read page size to 4096 bytes.
The local helper can span two pages when an element crosses a boundary. The macro is defined/undefined inside _TIFFPartialReadStripArray().
| #define TIFF_MAX | ( | a, | |
| b | |||
| ) | (((a) > (b)) ? (a) : (b)) |
Select the larger of two expressions.
Uses C comparison/conditional usual conversions. Each argument is evaluated in the comparison and the selected argument again; avoid side effects. Does not allocate or report diagnostics. Parenthesised expansion yields a value, not a checked size operation.
| [in] | a | First comparable expression; may be evaluated twice. |
| [in] | b | Second comparable expression; may be evaluated twice. |
| #define TIFF_MIN | ( | a, | |
| b | |||
| ) | (((a) < (b)) ? (a) : (b)) |
Select the smaller of two expressions.
Uses C comparison/conditional usual conversions. Each argument is evaluated in the comparison and the selected argument again; avoid side effects. Does not allocate or report diagnostics. Parenthesised expansion yields a value, not a checked size operation.
| [in] | a | First comparable expression; may be evaluated twice. |
| [in] | b | Second comparable expression; may be evaluated twice. |
|
static |
Grow paired strile caches and fetch an uncached value.
Requires consistent deferred entries and a strile index below td_nstrips and representable by int for the page reader. Expands both handle-owned arrays together, using UINT64_MAX as uncached sentinel, then loads a page if needed. On either realloc failure frees both current arrays and resets their capacity, losing old cache contents. Partial read failure stores zero at the requested slot, so later calls may return success with that cached zero. Can allocate, seek/read, diagnose, and invalidate borrowed array pointers. No ownership transfers.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | strile | Logical strile index in range. |
| [in] | dirent | Non-NULL external deferred entry with more than four elements. |
| [in,out] | parray | Pointer to the matching handle-owned offset or byte-count array slot. |
Definition at line 10375 of file tif_dirread.c.
References _TIFFfreeExt(), _TIFFPartialReadStripArray(), _TIFFreallocExt(), TIFFDirectory::td_stripoffsetbyteallocsize, TIFFDirEntry::tdir_count, tiff::tif_dir, TIFF_MAX, TIFF_MIN, TIFFErrorExtR(), and TIFFGetFileSize.
Referenced by _TIFFGetStrileOffsetOrByteCountValue().
|
extern |
Materialise deferred strile arrays when required.
Delegates to _TIFFFillStrilesInternal() with byte-count loading enabled. Lazy mode discards partial caches on first full load; replaces/allocates handle-owned arrays and may do I/O or report diagnostics. Clears deferred entries after the fetch attempt, including failure, so retry is not equivalent to the first call. Already loaded/chopped/non-deferred cases return one without validating all array contents. Borrowed array pointers may be invalidated. No ownership transfers.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
Definition at line 10602 of file tif_dirread.c.
References _TIFFFillStrilesInternal().
Referenced by _TIFFGetStrileOffsetOrByteCountValue(), _TIFFVGetField(), TIFFReadDirectory(), TIFFWriteCheck(), and TIFFWriteDirectorySec().
|
static |
Materialise deferred strile arrays or recognise an already-loaded state.
Returns one without work for non-deferred/chopped arrays. First full load in lazy mode frees both partial caches and marks lazy loading done. An existing offset array is treated as success without revalidating counts. Otherwise fetches offsets and optionally byte counts; clears both deferred entries after attempts, even on failure or when counts were not requested. Owns resulting arrays in the handle; borrowed views can be invalidated. Allocations/I/O/diagnostics and partial-state effects follow the fetch helpers; no rollback.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | loadStripByteCount | Nonzero to fetch counts too; zero for offset-only recovery. |
Definition at line 10625 of file tif_dirread.c.
References _TIFFfreeExt(), _TIFFmemset(), TIFFDirectory::td_nstrips, TIFFDirectory::td_stripbytecount_entry, TIFFDirectory::td_stripbytecount_p, TIFFDirectory::td_stripoffset_entry, TIFFDirectory::td_stripoffset_p, TIFFDirectory::td_stripoffsetbyteallocsize, TIFFDirEntry::tdir_count, tiff::tif_dir, tiff::tif_flags, TIFF_CHOPPEDUPARRAYS, TIFF_DEFERSTRILELOAD, TIFF_LAZYSTRILELOAD_ASKED, TIFF_LAZYSTRILELOAD_DONE, and TIFFFetchStripThing().
Referenced by _TIFFFillStriles(), and EstimateStripByteCounts().
|
static |
Resolve a cached, fully deferred, or lazy strile metadata value.
Validates index and consistency of the two small/large-entry paths. Loads full arrays or a lazy page as required, potentially freeing/reallocating paired caches. Initialises optional error status to zero; sets it for errors detected now, not historical cached failures. A failed full fill does not force an immediate zero if an array value remains available. No pixel decoding, ownership transfer, or range validation of the resulting file payload.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | strile | Zero-based logical strile index. |
| [in,out] | dirent | Borrowed matching deferred entry; may be cleared indirectly by full fill. |
| [in,out] | parray | Matching handle-owned offset/count array slot; may be replaced/cleared. |
| [out] | pbErr | Optional current-call error slot. |
Definition at line 10501 of file tif_dirread.c.
References _TIFFFetchStrileValue(), _TIFFFillStriles(), TIFFDirectory::td_nstrips, TIFFDirectory::td_stripbytecount_entry, TIFFDirectory::td_stripoffset_entry, TIFFDirEntry::tdir_count, tiff::tif_dir, tiff::tif_flags, TIFF_CHOPPEDUPARRAYS, TIFF_DEFERSTRILELOAD, TIFF_LAZYSTRILELOAD_ASKED, and TIFFErrorExtR().
Referenced by TIFFGetStrileByteCountWithErr(), and TIFFGetStrileOffsetWithErr().
|
static |
Load a strile value and neighbouring page entries into a cache.
Requires an external entry with count greater than four, a valid nonnegative cache index, and a sufficiently allocated panVals array. Accepts SHORT/LONG/LONG8 and nonconforming SLONG8; negative signed values are cast modulo 2^64 without a nonnegative range check. Uses a stack buffer for one/two 4096-byte pages, normalises endianness, and updates multiple cache elements. Errors can zero the target or leave partial/unchanged cache data; diagnostics vary and I/O position changes. Does not allocate or transfer ownership.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | dirent | Non-NULL deferred parsed entry with raw offset bytes. |
| [in] | strile | Index within the allocated logical cache; representable by int. |
| [in,out] | panVals | Writable borrowed uint64_t cache with td_stripoffsetbyteallocsize elements. |
Definition at line 10164 of file tif_dirread.c.
References _TIFFUnsanitizedAddUInt64AndInt(), IO_CACHE_PAGE_SIZE, SeekOK, TIFFDirectory::td_stripoffsetbyteallocsize, TIFFDirEntry::tdir_count, TIFFDirEntry::tdir_offset, TIFFDirEntry::tdir_type, tiff::tif_dir, tiff::tif_flags, TIFF_BIGTIFF, TIFF_LONG, TIFF_LONG8, TIFF_SHORT, TIFF_SLONG8, TIFF_SWAB, TIFFErrorExtR(), TIFFReadFile, TIFFSwabLong(), TIFFSwabLong8(), TIFFSwabShort(), TIFFDirEntry::toff_long, and TIFFDirEntry::toff_long8.
Referenced by _TIFFFetchStrileValue().
|
static |
Add a signed displacement with intentional unsigned wrap.
Uses modulo-2^64 arithmetic after converting b to uint64_t. No diagnostics, allocation, state, or ownership effects. The source disables unsigned-overflow sanitisation for this helper.
| [in] | a | Unsigned base value. |
| [in] | b | Signed displacement, including negative page-relative indices. |
Definition at line 10123 of file tif_dirread.c.
Referenced by _TIFFPartialReadStripArray().
|
static |
Replace uncompressed strip metadata with a logical subdivision.
Requires consistent existing contiguous uncompressed geometry and nonzero old/new strip counts. Computes the old total span, allocates both new arrays, and only then frees/replaces old arrays, adjusts counts and RowsPerStrip, and marks chopped arrays. Allocation/large-size rejection can diagnose; span rejection is silent and leaves old arrays. May load deferred old values first, so caches/I/O can change even on refusal. Ignores RowsPerStrip setter status. Arrays remain handle-owned and borrowed views can be invalidated; does not rewrite the on-disk IFD.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | nstrips | Positive new number of logical strips. |
| [in] | stripbytes | Requested full-strip bytes, clipped to remaining total span. |
| [in] | rowsperstrip | Positive logical row count per new strip. |
Definition at line 9816 of file tif_dirread.c.
References _TIFFCheckMalloc(), _TIFFfreeExt(), TIFFDirectory::td_nstrips, TIFFDirectory::td_stripbytecount_p, TIFFDirectory::td_stripoffset_p, TIFFDirectory::td_stripsperimage, tiff::tif_dir, tiff::tif_flags, TIFF_CHOPPEDUPARRAYS, TIFFGetFileSize, TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFSetField(), TIFFTAG_ROWSPERSTRIP, and TIFFWarningExtR().
Referenced by ChopUpSingleUncompressedStrip(), and TryChopUpUncompressedBigTiff().
|
static |
Try to subdivide one contiguous uncompressed strip.
Requires strip-chopping enabled, contiguous samples, one uncompressed non-tiled strip, and established geometry. Targets STRIP_SIZE_DEFAULT with rowblock/YCbCr alignment. Oversized geometry, suspicious file extents, or allocation failure can leave the original layout; diagnostics follow size/allocation helpers. May load metadata and change I/O/caches before declining. Successful replacement changes directory-owned strile arrays/RowsPerStrip without changing on-disk entries; old borrowed views may be invalidated.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
Definition at line 9929 of file tif_dirread.c.
References allocChoppedUpStripArrays(), isUpSampled, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, STRIP_SIZE_DEFAULT, TIFFDirectory::td_imagelength, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_ycbcrsubsampling, tiff::tif_dir, tiff::tif_mode, TIFFGetFileSize, TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFhowmany_32, and TIFFVTileSize64().
Referenced by TIFFReadDirectory().
|
static |
Read a strile array and pad permitted missing elements with zero.
Reads at most nstrips values into newly owned host-order uint64_t storage; excess entries are ignored. A short array warns and is zero-padded to nstrips when nstrips is within LIBTIFF_STRILE_ARRAY_MAX_RESIZE_COUNT (default one million; a malformed or out-of-range value keeps the default); otherwise an error is reported and zero is returned. A padded array larger than 100 MiB that also exceeds the file size is refused with a warning and zero is returned. Does not free prior *lpp; provide an empty slot. On failure frees new temporary data; conversion and allocation errors are reported. Success transfers an Ext allocation to be released with _TIFFfreeExt(tif,...); I/O position may change.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
| [in] | dir | Non-NULL parsed offset/count entry. |
| [in] | nstrips | Positive expected number of logical striles. |
| [out] | lpp | Non-NULL empty owner slot; assigned on success. |
Definition at line 9651 of file tif_dirread.c.
References _TIFFCheckMalloc(), _TIFFfreeExt(), _TIFFmemcpy(), _TIFFmemset(), _TIFFParseUInt32(), _TIFFField::field_name, TIFFDirEntry::tdir_count, TIFFDirEntry::tdir_tag, TIFFFieldWithTag(), TIFFGetFileSize, TIFFReadDirEntryErrCount, TIFFReadDirEntryErrOk, TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryOutputErr(), and TIFFWarningExtR().
Referenced by _TIFFFillStrilesInternal(), and TIFFReadDirectory().
|
static |
Try to subdivide huge contiguous uncompressed strip data.
Requires contiguous, non-tiled, uncompressed, chop-enabled geometry with strip size above INT32_MAX. Checks existing strip sizes/contiguity and rowblock bounds, then aims for 512 MiB logical strips, respecting YCbCr rowblocks. Refuses unsupported/suspicious cases without a status; allocation helpers can diagnose. May allocate/load metadata and change I/O/caches. On replacement directory arrays/RowsPerStrip change and borrowed views are invalidated; file bytes are unchanged.
| [in,out] | tif | Non-NULL live handle with matching schema/state; serialise access externally. |
Definition at line 10014 of file tif_dirread.c.
References allocChoppedUpStripArrays(), COMPRESSION_NONE, isUpSampled, PHOTOMETRIC_YCBCR, PLANARCONFIG_CONTIG, TIFFDirectory::td_compression, TIFFDirectory::td_imagelength, TIFFDirectory::td_nstrips, TIFFDirectory::td_photometric, TIFFDirectory::td_planarconfig, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_ycbcrsubsampling, tiff::tif_dir, tiff::tif_flags, tiff::tif_mode, TIFF_ISTILED, TIFF_STRIPCHOP, TIFFGetFileSize, TIFFGetStrileByteCount(), TIFFGetStrileOffset(), TIFFhowmany_32, TIFFStripSize64(), and TIFFVStripSize64().
Referenced by TIFFReadDirectory().