|
LibTIFF 4.7.2
TIFF library public API and implementation reference
|
Initialise directory state and track chain indices and file offsets. More...
Macros | |
| #define | CleanupField(member) |
| Release and clear one directory-owned allocation. | |
Functions | |
| static int | TIFFAdvanceDirectory (TIFF *tif, uint64_t *nextdiroff, uint64_t *off, tdir_t *nextdirnum) |
| Read one chain link and update traversal/map bookkeeping. | |
| void | _TIFFResetTifDirAndInitStrileCounters (TIFFDirectory *td) |
| Zero directory storage and initialise traversal sentinels. | |
| 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 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 | TIFFDefaultDirectory (TIFF *tif) |
| Install the image schema, default values, and core tag methods. | |
Initialise directory state and track chain indices and file offsets.
| #define CleanupField | ( | member | ) |
Release and clear one directory-owned allocation.
Source-local block macro capturing live tif and td variables. A NULL member is ignored; otherwise uses _TIFFfreeExt() with tif and clears the slot. The member selector is substituted three times; supply no side effects and only a compatible owned pointer. Does not alter scalar counts/flags or report a status. Borrowed views into released storage become invalid.
| [in,out] | member | Pointer-member selector relative to td, e.g. td_colormap[0]. |
Register or validate a chain index/offset pair for loop detection.
A known offset at a different index warns and fails; the same pair succeeds. A known index can be rebound to a new offset, removing the old shared record first. Enforces TIFF_MAX_DIR_COUNT when adding a new pair. Borrows the handle; no values or entry pointers are transferred to the caller. The offset map owns shared records and the number map borrows them. The maps, their nodes and the records are allocated with the handle's Ext allocators, so they count against its memory limits. A new record is inserted into both maps or into neither: if the second insertion fails, the record is removed from the first map again. Rebinding is not transactional, since the old record is removed before the replacement is allocated. Failure to create either hash map, or any other allocation/insertion failure, returns zero, sometimes without a direct diagnostic. Callers requiring recovery must discard/rebuild maps rather than assuming unchanged state.
| [in,out] | tif | Non-NULL live handle; caller must serialise access. |
| [in] | dirn | Chain-relative zero-based index. |
| [in] | diroff | Nonzero IFD offset in bytes; zero means chain end. |
Definition at line 7580 of file tif_dirread.c.
References _TIFFfreeExt(), _TIFFmallocExt(), TIFFOffsetAndDirNumber::dirNumber, equalFuncNumberToOffset(), equalFuncOffsetToNumber(), hashFuncNumberToOffset(), hashFuncOffsetToNumber(), insertOffsetAndDirNumber(), TIFFOffsetAndDirNumber::offset, tiff::tif_map_dir_number_to_offset, tiff::tif_map_dir_offset_to_number, TIFF_MAX_DIR_COUNT, TIFFErrorExtR(), TIFFHashSetLookup(), TIFFHashSetNew(), TIFFHashSetRemove(), TIFFHashSetSize(), and TIFFWarningExtR().
Referenced by TIFFAdvanceDirectory(), TIFFLinkDirectory(), TIFFReadDirectory(), TIFFRewriteDirectorySec(), TIFFSetSubDirectory(), and TIFFWriteDirectorySec().
Resolve a directory offset using the chain maps.
Returns immediately for offset zero or a missing offset map. If a map exists but lacks the offset, calls TIFFNumberOfDirectories() to scan the main chain and tries again; that can allocate, change maps/counts, move I/O position, and dispatch diagnostics. Does not load tag values. Output is assigned only on success; no ownership transfers.
| [in,out] | tif | Non-NULL live handle; caller must serialise access. |
| [in] | diroff | Directory offset in bytes. |
| [out] | dirn | Non-NULL index output; unchanged when no match is found. |
Definition at line 7719 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::dirNumber, TIFFOffsetAndDirNumber::offset, tiff::tif_map_dir_offset_to_number, TIFFHashSetLookup(), and TIFFNumberOfDirectories().
Referenced by TIFFLinkDirectory(), and TIFFSetSubDirectory().
Resolve an index from the existing number-to-offset map.
Does not populate a missing map, scan the file, allocate, emit diagnostics, or transfer ownership. A match is scoped to the currently cached chain and is not independent validation of file contents.
| [in] | tif | Non-NULL live handle; caller must serialise access. |
| [in] | dirn | Chain-relative zero-based index. |
| [out] | diroff | Non-NULL byte-offset output; unchanged on absence. |
Definition at line 7757 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::dirNumber, TIFFOffsetAndDirNumber::offset, tiff::tif_map_dir_number_to_offset, and TIFFHashSetLookup().
Referenced by TIFFSetDirectory().
|
extern |
Attempt to remove a shared directory-map entry by offset.
Treats absence as success. With both matching entries, attempts removal from the borrowing number map before removing/freeing the owning offset-map entry. A missing number map when the offset entry exists reports an error. Hash removal tolerates a failed shrink allocation, so a matching entry is always removed from both maps. If the number map exists without the expected key, the offset entry is left untouched and one is returned, so success does not prove removal. Does not change directory values/file contents or transfer ownership.
| [in,out] | tif | Non-NULL live handle; caller must serialise access. |
| [in] | diroff | Byte-offset key to remove; need not already be present. |
Definition at line 7778 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::dirNumber, TIFFOffsetAndDirNumber::offset, tiff::tif_map_dir_number_to_offset, tiff::tif_map_dir_offset_to_number, TIFFErrorExtR(), TIFFHashSetLookup(), and TIFFHashSetRemove().
Referenced by TIFFRewriteDirectorySec().
|
extern |
Zero directory storage and initialise traversal sentinels.
Does not free live owned pointers first; call only on fresh or already released storage. Sets row/column and strip/tile indices to their no-current sentinels, scanline size to zero, and tile size to minus one. Does not install semantic tag defaults, perform I/O, allocate, or emit diagnostics. No ownership is acquired.
| [in,out] | td | Non-NULL writable directory without live allocations. |
Definition at line 2151 of file tif_dir.c.
References _TIFFmemset(), NOSTRIP, NOTILE, TIFFDirectory::td_col, TIFFDirectory::td_curstrip, TIFFDirectory::td_curtile, TIFFDirectory::td_row, TIFFDirectory::td_scanlinesize, and TIFFDirectory::td_tilesize.
Referenced by TIFFClientOpenExt(), and TIFFDefaultDirectory().
|
static |
Compare directory-map records by directory index.
Uses only the directory index key; all records and key fields must remain live/stable while stored. No allocation, diagnostics, mutation, or ownership transfer occurs.
| [in] | elt1 | Non-NULL borrowed left record. |
| [in] | elt2 | Non-NULL borrowed right record. |
Definition at line 7532 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::dirNumber.
Referenced by _TIFFCheckDirNumberAndOffset().
|
static |
Compare directory-map records by offset.
Uses only the offset key; all records and key fields must remain live/stable while stored. No allocation, diagnostics, mutation, or ownership transfer occurs.
| [in] | elt1 | Non-NULL borrowed left record. |
| [in] | elt2 | Non-NULL borrowed right record. |
Definition at line 7491 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::offset.
Referenced by _TIFFCheckDirNumberAndOffset().
|
static |
Hash a directory-map directory index key.
Uses only the directory index key; all records and key fields must remain live/stable while stored. No allocation, diagnostics, mutation, or ownership transfer occurs. Returns the index as unsigned long.
| [in] | elt | Non-NULL borrowed TIFFOffsetAndDirNumber record. |
Definition at line 7512 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::dirNumber.
Referenced by _TIFFCheckDirNumberAndOffset().
|
static |
Hash a directory-map offset key.
Uses only the offset key; all records and key fields must remain live/stable while stored. No allocation, diagnostics, mutation, or ownership transfer occurs. XORs the upper and lower 32-bit offset halves.
| [in] | elt | Non-NULL borrowed TIFFOffsetAndDirNumber record. |
Definition at line 7469 of file tif_dirread.c.
References TIFFOffsetAndDirNumber::offset.
Referenced by _TIFFCheckDirNumberAndOffset().
|
static |
Add a directory-tracking record to both directory maps.
tif_map_dir_offset_to_number owns the record and releases it with _TIFFfreeExt(); tif_map_dir_number_to_offset only borrows it. If the second insertion fails, the record is removed from the first map again, so both maps always hold the same records. Each failure is reported through TIFFErrorExtR() under the _TIFFCheckDirNumberAndOffset module name.
| [in,out] | tif | Non-NULL handle whose two maps already exist. |
| [in] | entryPtr | Record allocated with _TIFFmallocExt() for tif. Ownership passes to the maps in all cases: after a failure the record has been released and the caller must neither use nor free it. |
Definition at line 7557 of file tif_dirread.c.
References tiff::tif_map_dir_number_to_offset, tiff::tif_map_dir_offset_to_number, TIFFErrorExtR(), TIFFHashSetInsert(), and TIFFHashSetRemove().
Referenced by _TIFFCheckDirNumberAndOffset().
|
static |
Read one chain link and update traversal/map bookkeeping.
Reads a mapped IFD or uses client seek/read callbacks without loading tag values. Validates/registers the starting pair and, for a nonzero next link, the following pair. A loop at the next link warns, clears that link, backs up its index, and still succeeds; a rejected starting pair errors, clears offset/index, and fails. Count/range/read failures dispatch diagnostics but leave outputs and map/I/O state partially changed; off may already be assigned. BigTIFF counts are limited to
| [in,out] | tif | Non-NULL live handle; caller must serialise access. |
| [in,out] | nextdiroff | Non-NULL current nonzero IFD offset on entry; following offset (zero at chain end) on success. Not generally preserved on failure. |
| [out] | off | Optional byte-offset output locating the current IFD's next-link field; valid only after success. |
| [in,out] | nextdirnum | Non-NULL chain index associated with the input offset; incremented only for an accepted nonzero next link. |
Definition at line 2428 of file tif_dir.c.
References _TIFFCheckDirNumberAndOffset(), _TIFFmemcpy(), isMapped, ReadOK, SeekOK, tiff::tif_base, tiff::tif_flags, tiff::tif_name, tiff::tif_size, TIFF_BIGTIFF, TIFF_SWAB, TIFF_TMSIZE_T_MAX, TIFFErrorExtR(), TIFFSeekFile, TIFFSwabLong(), TIFFSwabLong8(), TIFFSwabShort(), and TIFFWarningExtR().
Referenced by TIFFNumberOfDirectories(), TIFFSetDirectory(), and TIFFUnlinkDirectory().
|
extern |
Install the image schema, default values, and core tag methods.
Requires already released directory allocations: resets the directory structure without freeing its old pointer members. Replaces field schemas, frees compatibility descriptor batches, restores core get/set methods and postdecode handling, invokes the global extender, and attempts COMPRESSION_NONE setup. Clears dirty-directory and tiled flags afterwards. Can allocate and invalidate descriptors; extender/codec calls can alter state and report diagnostics. Schema/setup and compression-set failures are not propagated; this is initialisation, not a checked transaction.
| [in,out] | tif | Non-NULL live handle; caller must serialise access. |
Definition at line 2316 of file tif_dir.c.
References _TIFFextender, _TIFFfreeExt(), _TIFFGetFields(), _TIFFNoPostDecode(), _TIFFResetTifDirAndInitStrileCounters(), _TIFFSetupFields(), _TIFFVGetField(), _TIFFVSetField(), _TIFFFieldArray::allocated_size, COMPRESSION_NONE, _TIFFFieldArray::fields, FILLORDER_MSB2LSB, ORIENTATION_TOPLEFT, PLANARCONFIG_CONTIG, TIFFTagMethods::printdir, RESUNIT_INCH, SAMPLEFORMAT_UINT, TIFFDirectory::td_bitspersample, TIFFDirectory::td_compression, TIFFDirectory::td_extrasamples, TIFFDirectory::td_fillorder, TIFFDirectory::td_imagedepth, TIFFDirectory::td_maxsamplevalue, TIFFDirectory::td_minsamplevalue, TIFFDirectory::td_orientation, TIFFDirectory::td_planarconfig, TIFFDirectory::td_resolutionunit, TIFFDirectory::td_rowsperstrip, TIFFDirectory::td_sampleformat, TIFFDirectory::td_sampleinfo, TIFFDirectory::td_samplesperpixel, TIFFDirectory::td_subfiletype, TIFFDirectory::td_threshholding, TIFFDirectory::td_tiledepth, TIFFDirectory::td_tilelength, TIFFDirectory::td_tilewidth, TIFFDirectory::td_ycbcrpositioning, TIFFDirectory::td_ycbcrsubsampling, THRESHHOLD_BILEVEL, tiff::tif_dir, tiff::tif_fieldscompat, tiff::tif_flags, tiff::tif_foundfield, tiff::tif_nfieldscompat, tiff::tif_postdecode, tiff::tif_tagmethods, tiffFieldArray, TIFFSetField(), TIFFTAG_COMPRESSION, TIFFTagMethods::vgetfield, TIFFTagMethods::vsetfield, and YCBCRPOSITION_CENTERED.
Referenced by TIFFClientOpenExt(), TIFFCreateCustomDirectory(), TIFFCreateDirectory(), TIFFReadCustomDirectory(), TIFFReadDirectory(), and TIFFUnlinkDirectory().