LibTIFF 4.7.2
TIFF library public API and implementation reference
Loading...
Searching...
No Matches
Macros | Functions
Checked allocation and array copies

Apply handle allocation policies and manage owned array replacements. More...

Collaboration diagram for Checked allocation and array copies:

Macros

#define LEADING_AREA_TO_STORE_ALLOC_SIZE   (2 * SIZEOF_SIZE_T)
 Reserve two size_t widths before a cumulatively tracked payload.
 

Functions

static void setByteArray (TIFF *tif, void **vpp, const void *vp, size_t nmemb, size_t elem_size)
 Discard an old allocation and copy a replacement byte product.
 
static void _TIFFsetNString (TIFF *tif, char **cpp, const char *cp, uint32_t n)
 Replace an owned string byte sequence with a copy.
 
static void _TIFFsetLong8Array (TIFF *tif, uint64_t **lpp, const uint64_t *lp, uint32_t n)
 Replace an owned 64-bit integer array with a copy.
 
static void setDoubleArrayOneValue (TIFF *tif, double **vpp, double value, size_t nmemb)
 Replace an owned double array with one repeated value.
 
static int setShortArrayWithCount (TIFF *tif, uint16_t **wpp, uint32_t *countp, const uint16_t *wp, uint32_t n)
 Install a short array together with the number of elements it holds.
 
static void _TIFFEmitErrorAboveMaxSingleMemAlloc (TIFF *tif, const char *pszFunction, tmsize_t s)
 Report a rejected single allocation-policy check.
 
static void _TIFFEmitErrorAboveMaxCumulatedMemAlloc (TIFF *tif, const char *pszFunction, tmsize_t s)
 Report a rejected cumulative allocation-policy check.
 
void _TIFFsetByteArray (void **vpp, const void *vp, uint32_t n)
 Replace an owned byte array with a copied array.
 
void _TIFFsetByteArrayExt (TIFF *tif, void **vpp, const void *vp, uint32_t n)
 Replace an owned byte array with a copied array.
 
void _TIFFsetShortArray (uint16_t **wpp, const uint16_t *wp, uint32_t n)
 Replace an owned short array with a copied array.
 
void _TIFFsetShortArrayExt (TIFF *tif, uint16_t **wpp, const uint16_t *wp, uint32_t n)
 Replace an owned short array with a copied array.
 
void _TIFFsetLongArray (uint32_t **lpp, const uint32_t *lp, uint32_t n)
 Replace an owned long array with a copied array.
 
void _TIFFsetLongArrayExt (TIFF *tif, uint32_t **lpp, const uint32_t *lp, uint32_t n)
 Replace an owned long array with a copied array.
 
void _TIFFsetFloatArray (float **fpp, const float *fp, uint32_t n)
 Replace an owned float array with a copied array.
 
void _TIFFsetFloatArrayExt (TIFF *tif, float **fpp, const float *fp, uint32_t n)
 Replace an owned float array with a copied array.
 
void _TIFFsetDoubleArray (double **dpp, const double *dp, uint32_t n)
 Replace an owned double array with a copied array.
 
void _TIFFsetDoubleArrayExt (TIFF *tif, double **dpp, const double *dp, uint32_t n)
 Replace an owned double array with a copied array.
 
void _TIFFfreeExt (TIFF *tif, void *p)
 Release a handle-aware allocation and its payload charge.
 
void * _TIFFmallocExt (TIFF *tif, tmsize_t s)
 Allocate uninitialised bytes under a handle's allocation policy.
 
void * _TIFFcallocExt (TIFF *tif, tmsize_t nmemb, tmsize_t siz)
 Allocate a zero-filled array under a handle's allocation policy.
 
void * _TIFFreallocExt (TIFF *tif, void *p, tmsize_t s)
 Resize a handle-aware block or release it for a nonpositive size.
 
void * _TIFFCheckMalloc (TIFF *tif, tmsize_t nmemb, tmsize_t elem_size, const char *what)
 Allocate a checked array with an allocation-failure diagnostic.
 
void * _TIFFCheckRealloc (TIFF *tif, void *buffer, tmsize_t nmemb, tmsize_t elem_size, const char *what)
 Resize a checked array with an allocation-failure diagnostic.
 

Detailed Description

Apply handle allocation policies and manage owned array replacements.

Macro Definition Documentation

◆ LEADING_AREA_TO_STORE_ALLOC_SIZE

#define LEADING_AREA_TO_STORE_ALLOC_SIZE   (2 * SIZEOF_SIZE_T)

Reserve two size_t widths before a cumulatively tracked payload.

Private accounting/alignment prefix; callers must not access or infer it.

Definition at line 193 of file tif_open.c.

Function Documentation

◆ _TIFFcallocExt()

void * _TIFFcallocExt ( TIFF *  tif,
tmsize_t  nmemb,
tmsize_t  siz 
)
extern

Allocate a zero-filled array under a handle's allocation policy.

Use the same handle and accounting configuration for allocation, reallocation, and release. A cumulatively tracked block contains a private prefix and cannot be passed to _TIFFfree() or another handle's allocator. Release all such blocks before releasing their handle. NULL tif selects untracked allocation and is valid only with matching untracked blocks.

Checks signed-size product representability before allocating. Limit failures emit diagnostics; invalid/overflowing products and ordinary allocator failure have no direct diagnostic. Successful cumulative accounting charges only payload bytes. Does not retain inputs or perform file I/O.

Parameters
[in,out]tifLive accounting handle, or NULL for untracked allocation.
[in]nmembRequested element count.
[in]sizElement size in bytes.
Returns
An owned zero-filled block for _TIFFfreeExt(), or NULL for nonpositive operands, a product beyond TIFF_TMSIZE_T_MAX, limit/prefix rejection, or allocator failure.

Definition at line 224 of file tif_open.c.

References _TIFFcalloc(), _TIFFEmitErrorAboveMaxCumulatedMemAlloc(), _TIFFEmitErrorAboveMaxSingleMemAlloc(), LEADING_AREA_TO_STORE_ALLOC_SIZE, tiff::tif_cur_cumulated_mem_alloc, tiff::tif_max_cumulated_mem_alloc, tiff::tif_max_single_mem_alloc, and TIFF_TMSIZE_T_MAX.

Referenced by _TIFFReadEncodedStripAndAllocBuffer(), OJPEGWriteHeaderInfo(), TIFFHashSetNew(), TIFFHashSetRehash(), TIFFInitLERC(), TIFFInitZIP(), TIFFReadBufferSetup(), and TIFFReadDirectory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFCheckMalloc()

void * _TIFFCheckMalloc ( TIFF *  tif,
tmsize_t  nmemb,
tmsize_t  elem_size,
const char *  what 
)
extern

Allocate a checked array with an allocation-failure diagnostic.

Checks the product through _TIFFMultiplySSize() with its optional arithmetic diagnostic disabled, then delegates to _TIFFreallocExt(). Zero/negative operands and overflowing products are rejected without calling realloc. Any NULL result emits an allocation diagnostic using tif->tif_name and what; limit rejection can therefore produce both a limit and an allocation diagnostic.

Equivalent to _TIFFCheckRealloc() with buffer = NULL. The returned block is uninitialised and must be released with _TIFFfreeExt() and the same handle.

Parameters
[in,out]tifNon-NULL live TIFF handle for allocation policy and diagnostics.
[in]nmembPositive element count.
[in]elem_sizePositive element size in bytes.
[in]whatNon-NULL borrowed allocation-purpose description for diagnostics.
Returns
An owned block on success, or NULL on invalid/overflowing size, a policy limit, or allocator failure.

Definition at line 274 of file tif_aux.c.

References _TIFFCheckRealloc().

Referenced by _TIFFMergeFields(), _TIFFRewriteField(), _TIFFVSetField(), allocChoppedUpStripArrays(), EstimateStripByteCounts(), JPEGDecodeRaw(), TIFFFetchDirectory(), TIFFFetchStripThing(), TIFFMergeFieldInfo(), TIFFPrintDirectory(), TIFFReadDirEntryArrayWithLimit(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFSetClientInfo(), TIFFSetupStrips(), TIFFWriteDirectorySec(), TIFFWriteDirectoryTagCheckedRationalArray(), TIFFWriteDirectoryTagCheckedRationalDoubleArray(), TIFFWriteDirectoryTagCheckedSrationalArray(), TIFFWriteDirectoryTagCheckedSrationalDoubleArray(), TIFFWriteDirectoryTagColormap(), TIFFWriteDirectoryTagIfdIfd8Array(), TIFFWriteDirectoryTagLong8Array(), TIFFWriteDirectoryTagLongLong8Array(), TIFFWriteDirectoryTagSampleformatArray(), TIFFWriteDirectoryTagShortPerSample(), TIFFWriteDirectoryTagSlong8Array(), TIFFWriteDirectoryTagSubifd(), and TIFFWriteDirectoryTagTransferfunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFCheckRealloc()

void * _TIFFCheckRealloc ( TIFF *  tif,
void *  buffer,
tmsize_t  nmemb,
tmsize_t  elem_size,
const char *  what 
)
extern

Resize a checked array with an allocation-failure diagnostic.

Checks the product through _TIFFMultiplySSize() with its optional arithmetic diagnostic disabled, then delegates to _TIFFreallocExt(). Zero/negative operands and overflowing products are rejected without calling realloc. Any NULL result emits an allocation diagnostic using tif->tif_name and what; limit rejection can therefore produce both a limit and an allocation diagnostic.

On any NULL result the old positive-size allocation remains owned and valid, including a rejected zero request; unlike _TIFFreallocExt(s <= 0), a zero count does not free it. Success invalidates the old pointer and returns storage for _TIFFfreeExt() with the matching handle. Preserve the old pointer until success.

Parameters
[in,out]tifNon-NULL live TIFF handle for allocation policy and diagnostics.
[in]bufferMatching handle-aware allocation to resize, or NULL.
[in]nmembPositive element count.
[in]elem_sizePositive element size in bytes.
[in]whatNon-NULL borrowed allocation-purpose description for diagnostics.
Returns
An owned block on success, or NULL on invalid/overflowing size, a policy limit, or allocator failure.

Definition at line 249 of file tif_aux.c.

References _TIFFMultiplySSize(), _TIFFreallocExt(), tiff::tif_name, TIFF_SSIZE_FORMAT, and TIFFErrorExtR().

Referenced by _TIFFCheckMalloc(), _TIFFMergeFields(), PixarLogEncode(), and TIFFMergeFieldInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFEmitErrorAboveMaxCumulatedMemAlloc()

static void _TIFFEmitErrorAboveMaxCumulatedMemAlloc ( TIFF *  tif,
const char *  pszFunction,
tmsize_t  s 
)
static

Report a rejected cumulative allocation-policy check.

Formats the stored limit and size values through TIFFErrorExtR(). Does not allocate, free, update accounting, or decide the caller's return status. Diagnostic callbacks may have their normal side effects.

Parameters
[in]tifNon-NULL handle whose current cumulated total and cumulated limit are reported.
[in]pszFunctionBorrowed diagnostic module name.
[in]sRequested payload bytes, or additional payload growth for cumulative realloc reporting.

Definition at line 166 of file tif_open.c.

References tiff::tif_cur_cumulated_mem_alloc, tiff::tif_max_cumulated_mem_alloc, and TIFFErrorExtR().

Referenced by _TIFFcallocExt(), _TIFFmallocExt(), and _TIFFreallocExt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFEmitErrorAboveMaxSingleMemAlloc()

static void _TIFFEmitErrorAboveMaxSingleMemAlloc ( TIFF *  tif,
const char *  pszFunction,
tmsize_t  s 
)
static

Report a rejected single allocation-policy check.

Formats the stored limit and size values through TIFFErrorExtR(). Does not allocate, free, update accounting, or decide the caller's return status. Diagnostic callbacks may have their normal side effects.

Parameters
[in]tifNon-NULL handle whose tif_max_single_mem_alloc is reported.
[in]pszFunctionBorrowed diagnostic module name.
[in]sRequested payload bytes that exceeded the single-allocation limit.

Definition at line 141 of file tif_open.c.

References tiff::tif_max_single_mem_alloc, and TIFFErrorExtR().

Referenced by _TIFFcallocExt(), _TIFFmallocExt(), and _TIFFreallocExt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFfreeExt()

void _TIFFfreeExt ( TIFF *  tif,
void *  p 
)
extern

Release a handle-aware allocation and its payload charge.

Use the same handle and accounting configuration for allocation, reallocation, and release. A cumulatively tracked block contains a private prefix and cannot be passed to _TIFFfree() or another handle's allocator. Release all such blocks before releasing their handle. NULL tif selects untracked allocation and is valid only with matching untracked blocks.

NULL p is accepted. For a tracked block, reads its private prefix, subtracts the recorded payload size, and frees the underlying allocation. Invalidates all pointers into the block. There is no status result or direct diagnostic; debug assertions check accounting consistency. A wrong family/handle is not detected safely.

Parameters
[in,out]tifMatching live accounting handle, or NULL for an untracked block.
[in]pOwned matching allocation, or NULL.

Definition at line 301 of file tif_open.c.

References _TIFFfree(), LEADING_AREA_TO_STORE_ALLOC_SIZE, tiff::tif_cur_cumulated_mem_alloc, and tiff::tif_max_cumulated_mem_alloc.

Referenced by _TIFFCheckDirNumberAndOffset(), _TIFFCreateAnonField(), _TIFFFetchStrileValue(), _TIFFFillStrilesInternal(), _TIFFreallocExt(), _TIFFRewriteField(), _TIFFSetupFields(), _TIFFVSetField(), allocChoppedUpStripArrays(), cancelColorMap(), cancelTransferFunction(), EstimateStripByteCounts(), fpAcc(), fpDiff(), gtStripContig(), gtStripSeparate(), gtTileContig(), gtTileSeparate(), initCIELabConversion(), JPEGCleanup(), JPEGDecodeRaw(), JPEGEncode(), JPEGFixupTagsSubsampling(), LERCCleanup(), LERCPostEncode(), LERCPreDecode(), LogL16InitState(), LogLuvCleanup(), LogLuvClose(), LogLuvInitState(), LZMACleanup(), LZWCleanup(), OJPEGCleanup(), OJPEGReadHeaderInfoSecStreamDht(), OJPEGReadHeaderInfoSecStreamDqt(), OJPEGReadHeaderInfoSecTablesAcTable(), OJPEGReadHeaderInfoSecTablesDcTable(), OJPEGReadHeaderInfoSecTablesQTable(), PackBitsPostEncode(), PixarLogCleanup(), PixarLogClose(), PixarLogMakeTables(), PixarLogSetupDecode(), PredictorEncodeRow(), PredictorEncodeTile(), setByteArray(), setDoubleArrayOneValue(), SetupBuffers(), setupMap(), TIFF_zfree(), TIFFAppendToStrip(), TIFFCleanup(), TIFFClientOpenExt(), TIFFDefaultDirectory(), TIFFDefaultTransferFunction(), TIFFFetchDirectory(), TIFFFetchNormalTag(), TIFFFetchStripThing(), TIFFFillStrip(), TIFFFillTile(), TIFFFreeDirectory(), TIFFGetConfiguredCODECs(), TIFFHashSetClearInternal(), TIFFHashSetDestroy(), TIFFHashSetNew(), TIFFHashSetRehash(), TIFFHashSetReturnListElt(), TIFFjpeg_tables_dest(), TIFFListDestroy(), TIFFPrintDirectory(), TIFFReadAndRealloc(), TIFFReadBufferSetup(), TIFFReadCustomDirectory(), TIFFReadDirectory(), TIFFReadDirEntryArrayWithLimit(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntryFloatArray(), TIFFReadDirEntryIfd8Array(), TIFFReadDirEntryLong8ArrayWithLimit(), TIFFReadDirEntryLongArray(), TIFFReadDirEntryPersampleShort(), TIFFReadDirEntrySbyteArray(), TIFFReadDirEntryShortArray(), TIFFReadDirEntrySlong8Array(), TIFFReadDirEntrySlongArray(), TIFFReadDirEntrySshortArray(), TIFFRGBAImageEnd(), TIFFSetClientInfo(), TIFFSetupStrips(), TIFFUnlinkDirectory(), TIFFUnRegisterCODEC(), TIFFUnsetField(), TIFFWriteBufferSetup(), TIFFWriteDirectorySec(), TIFFWriteDirectoryTagCheckedRationalArray(), TIFFWriteDirectoryTagCheckedRationalDoubleArray(), TIFFWriteDirectoryTagCheckedSrationalArray(), TIFFWriteDirectoryTagCheckedSrationalDoubleArray(), TIFFWriteDirectoryTagColormap(), TIFFWriteDirectoryTagIfdIfd8Array(), TIFFWriteDirectoryTagLong8Array(), TIFFWriteDirectoryTagLongLong8Array(), TIFFWriteDirectoryTagSampleformatArray(), TIFFWriteDirectoryTagShortPerSample(), TIFFWriteDirectoryTagSlong8Array(), TIFFWriteDirectoryTagSubifd(), TIFFWriteDirectoryTagTransferfunction(), TWebPCleanup(), TWebPDecode(), TWebPPreEncode(), TWebPSetupDecode(), ZIPCleanup(), and ZSTDCleanup().

Here is the call graph for this function:

◆ _TIFFmallocExt()

void * _TIFFmallocExt ( TIFF *  tif,
tmsize_t  s 
)
extern

Allocate uninitialised bytes under a handle's allocation policy.

Use the same handle and accounting configuration for allocation, reallocation, and release. A cumulatively tracked block contains a private prefix and cannot be passed to _TIFFfree() or another handle's allocator. Release all such blocks before releasing their handle. NULL tif selects untracked allocation and is valid only with matching untracked blocks.

Positive configured limits are checked before allocation. Cumulative accounting tracks payload bytes and updates only after successful allocation; the prefix itself is not charged. Limit failures emit a diagnostic. Nonpositive size and ordinary allocator exhaustion return NULL without a direct diagnostic. Does not perform file I/O.

Parameters
[in,out]tifLive accounting handle, or NULL for untracked allocation.
[in]sRequested payload byte count.
Returns
An owned block for _TIFFfreeExt(tif, ...), or NULL for nonpositive size, a rejected limit/prefix check, or allocator failure.

Definition at line 195 of file tif_open.c.

References _TIFFEmitErrorAboveMaxCumulatedMemAlloc(), _TIFFEmitErrorAboveMaxSingleMemAlloc(), _TIFFmalloc(), LEADING_AREA_TO_STORE_ALLOC_SIZE, tiff::tif_cur_cumulated_mem_alloc, tiff::tif_max_cumulated_mem_alloc, tiff::tif_max_single_mem_alloc, and TIFF_TMSIZE_T_MAX.

Referenced by _TIFFCheckDirNumberAndOffset(), _TIFFCreateAnonField(), _TIFFReadEncodedTileAndAllocBuffer(), BuildMapBitdepth16To8(), BuildMapUaToAa(), fpAcc(), fpDiff(), initCIELabConversion(), initYCbCrConversion(), JPEGEncode(), JPEGFixupTagsSubsampling(), LERCPostEncode(), LERCPreDecode(), LogL16InitState(), LogLuvInitState(), LZWSetupDecode(), LZWSetupEncode(), makebwmap(), makecmap(), OJPEGPreDecodeSkipScanlines(), OJPEGReadHeaderInfoSecStreamDht(), OJPEGReadHeaderInfoSecStreamDqt(), OJPEGReadHeaderInfoSecTablesAcTable(), OJPEGReadHeaderInfoSecTablesDcTable(), OJPEGReadHeaderInfoSecTablesQTable(), OJPEGWriteHeaderInfo(), PackBitsPreEncode(), PixarLogMakeTables(), PixarLogSetupDecode(), PredictorEncodeRow(), PredictorEncodeTile(), setByteArray(), setDoubleArrayOneValue(), SetupBuffers(), setupMap(), TIFF_zalloc(), TIFFAppendToStrip(), TIFFClientOpenExt(), TIFFDefaultRefBlackWhite(), TIFFDefaultTransferFunction(), TIFFFetchNormalTag(), TIFFHashSetGetNewListElt(), TIFFHashSetNew(), TIFFInitJPEG(), TIFFInitLZMA(), TIFFInitLZW(), TIFFInitOJPEG(), TIFFInitPixarLog(), TIFFInitSGILog(), TIFFInitWebP(), TIFFInitZSTD(), TIFFjpeg_tables_dest(), TIFFReadCustomDirectory(), TIFFReadDirectory(), TIFFReadDirEntryByteArray(), TIFFReadDirEntryDoubleArray(), TIFFReadDirEntrySbyteArray(), TIFFRegisterCODEC(), TIFFRGBAImageBegin(), TIFFWriteBufferSetup(), TIFFWriteDirectorySec(), TWebPDecode(), and TWebPPreEncode().

Here is the call graph for this function:

◆ _TIFFreallocExt()

void * _TIFFreallocExt ( TIFF *  tif,
void *  p,
tmsize_t  s 
)
extern

Resize a handle-aware block or release it for a nonpositive size.

Use the same handle and accounting configuration for allocation, reallocation, and release. A cumulatively tracked block contains a private prefix and cannot be passed to _TIFFfree() or another handle's allocator. Release all such blocks before releasing their handle. NULL tif selects untracked allocation and is valid only with matching untracked blocks.

Preserves the initial min(old size, s) bytes on success; the old pointer becomes invalid even if the address is unchanged. Grown bytes are uninitialised. Check through a temporary result pointer. Successful cumulative accounting replaces the old payload charge with the new one. Limit failures emit diagnostics; ordinary exhaustion does not directly report an error. Does not perform file I/O.

Parameters
[in,out]tifMatching live accounting handle, or NULL for an untracked block.
[in]pMatching handle-aware allocation, or NULL.
[in]sNew payload byte count; a nonpositive value releases p.
Returns
The owned replacement on positive-size success. NULL with positive s preserves p and its accounting; NULL with s <= 0 means p was released and is invalid.

Definition at line 257 of file tif_open.c.

References _TIFFEmitErrorAboveMaxCumulatedMemAlloc(), _TIFFEmitErrorAboveMaxSingleMemAlloc(), _TIFFfreeExt(), _TIFFrealloc(), LEADING_AREA_TO_STORE_ALLOC_SIZE, tiff::tif_cur_cumulated_mem_alloc, tiff::tif_max_cumulated_mem_alloc, tiff::tif_max_single_mem_alloc, and TIFF_TMSIZE_T_MAX.

Referenced by _TIFFCheckRealloc(), _TIFFFetchStrileValue(), _TIFFVSetField(), SetupBuffers(), tables_empty_output_buffer(), TIFFGetConfiguredCODECs(), TIFFGrowStrips(), TIFFReadAndRealloc(), and TIFFReadDirEntryDataAndRealloc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetByteArray()

void _TIFFsetByteArray ( void **  vpp,
const void *  vp,
uint32_t  n 
)
extern

Replace an owned byte array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses the untracked family through a NULL handle. Release the replacement with _TIFFfree(). Returns no status, and no diagnostic is emitted on any failure. No file I/O occurs.

Parameters
[in,out]vppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]vpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count in bytes.

Definition at line 103 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetByteArrayExt()

void _TIFFsetByteArrayExt ( TIFF *  tif,
void **  vpp,
const void *  vp,
uint32_t  n 
)
extern

Replace an owned byte array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses handle-aware allocation/free and must preserve the same accounting context. Release the replacement with _TIFFfreeExt() using that context. Returns no status. Product rejection and ordinary allocation failure have no direct diagnostic; handle limit failures may report through the allocation helpers. No file I/O occurs.

Parameters
[in,out]tifMatching live accounting handle, or NULL for untracked storage.
[in,out]vppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]vpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count in bytes.

Definition at line 107 of file tif_dir.c.

References setByteArray().

Referenced by JPEGVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetDoubleArray()

void _TIFFsetDoubleArray ( double **  dpp,
const double *  dp,
uint32_t  n 
)
extern

Replace an owned double array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses the untracked family through a NULL handle. Release the replacement with _TIFFfree(). Returns no status, and no diagnostic is emitted on any failure. No file I/O occurs.

Parameters
[in,out]dppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]dpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 180 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetDoubleArrayExt()

void _TIFFsetDoubleArrayExt ( TIFF *  tif,
double **  dpp,
const double *  dp,
uint32_t  n 
)
extern

Replace an owned double array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses handle-aware allocation/free and must preserve the same accounting context. Release the replacement with _TIFFfreeExt() using that context. Returns no status. Product rejection and ordinary allocation failure have no direct diagnostic; handle limit failures may report through the allocation helpers. No file I/O occurs.

Parameters
[in,out]tifMatching live accounting handle, or NULL for untracked storage.
[in,out]dppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]dpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 184 of file tif_dir.c.

References setByteArray().

Referenced by _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetFloatArray()

void _TIFFsetFloatArray ( float **  fpp,
const float *  fp,
uint32_t  n 
)
extern

Replace an owned float array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses the untracked family through a NULL handle. Release the replacement with _TIFFfree(). Returns no status, and no diagnostic is emitted on any failure. No file I/O occurs.

Parameters
[in,out]fppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]fpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 171 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetFloatArrayExt()

void _TIFFsetFloatArrayExt ( TIFF *  tif,
float **  fpp,
const float *  fp,
uint32_t  n 
)
extern

Replace an owned float array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses handle-aware allocation/free and must preserve the same accounting context. Release the replacement with _TIFFfreeExt() using that context. Returns no status. Product rejection and ordinary allocation failure have no direct diagnostic; handle limit failures may report through the allocation helpers. No file I/O occurs.

Parameters
[in,out]tifMatching live accounting handle, or NULL for untracked storage.
[in,out]fppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]fpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 175 of file tif_dir.c.

References setByteArray().

Referenced by _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetLong8Array()

static void _TIFFsetLong8Array ( TIFF *  tif,
uint64_t **  lpp,
const uint64_t *  lp,
uint32_t  n 
)
static

Replace an owned 64-bit integer array with a copy.

Delegates to setByteArray() with its destructive replacement, checked- product, ownership, and diagnostic rules. Allocation failure loses the old allocation and leaves a NULL result slot. Returns no status.

Parameters
[in,out]tifMatching live accounting handle, or NULL.
[in,out]lppNon-NULL owned-allocation slot; cleared before copying.
[in]lpReadable source, or NULL to clear; may point into the old allocation.
[in]nNumber of uint64_t elements.

Definition at line 165 of file tif_dir.c.

References setByteArray().

Referenced by _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetLongArray()

void _TIFFsetLongArray ( uint32_t **  lpp,
const uint32_t *  lp,
uint32_t  n 
)
extern

Replace an owned long array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses the untracked family through a NULL handle. Release the replacement with _TIFFfree(). Returns no status, and no diagnostic is emitted on any failure. No file I/O occurs.

Parameters
[in,out]lppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]lpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 141 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetLongArrayExt()

void _TIFFsetLongArrayExt ( TIFF *  tif,
uint32_t **  lpp,
const uint32_t *  lp,
uint32_t  n 
)
extern

Replace an owned long array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses handle-aware allocation/free and must preserve the same accounting context. Release the replacement with _TIFFfreeExt() using that context. Returns no status. Product rejection and ordinary allocation failure have no direct diagnostic; handle limit failures may report through the allocation helpers. No file I/O occurs.

Parameters
[in,out]tifMatching live accounting handle, or NULL for untracked storage.
[in,out]lppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]lpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 145 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetNString()

static void _TIFFsetNString ( TIFF *  tif,
char **  cpp,
const char *  cp,
uint32_t  n 
)
static

Replace an owned string byte sequence with a copy.

Delegates to setByteArray() with its destructive replacement, checked- product, ownership, and diagnostic rules. Allocation failure loses the old allocation and leaves a NULL result slot. Returns no status.

Parameters
[in,out]tifMatching live accounting handle, or NULL.
[in,out]cppNon-NULL owned-allocation slot; cleared before copying.
[in]cpReadable source, or NULL to clear; may point into the old allocation.
[in]nNumber of bytes; no terminator is added.

Definition at line 126 of file tif_dir.c.

References setByteArray().

Referenced by _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _TIFFsetShortArray()

void _TIFFsetShortArray ( uint16_t **  wpp,
const uint16_t *  wp,
uint32_t  n 
)
extern

Replace an owned short array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses the untracked family through a NULL handle. Release the replacement with _TIFFfree(). Returns no status, and no diagnostic is emitted on any failure. No file I/O occurs.

Parameters
[in,out]wppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]wpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 131 of file tif_dir.c.

References setByteArray().

Here is the call graph for this function:

◆ _TIFFsetShortArrayExt()

void _TIFFsetShortArrayExt ( TIFF *  tif,
uint16_t **  wpp,
const uint16_t *  wp,
uint32_t  n 
)
extern

Replace an owned short array with a copied array.

Detaches the old destination, copies into a new allocation, and then frees the old one. A NULL source, zero/rejected byte product, or allocation failure leaves the destination NULL; the old data is still freed and lost. This is not a failure-preserving realloc operation. The source pointer is borrowed only during the copy; because the copy precedes the free, it may point into the old destination allocation.

Uses handle-aware allocation/free and must preserve the same accounting context. Release the replacement with _TIFFfreeExt() using that context. Returns no status. Product rejection and ordinary allocation failure have no direct diagnostic; handle limit failures may report through the allocation helpers. No file I/O occurs.

Parameters
[in,out]tifMatching live accounting handle, or NULL for untracked storage.
[in,out]wppNon-NULL pointer to an owned compatible array or NULL array pointer; replaced or cleared.
[in]wpReadable source for n elements, or NULL to clear; may point into the old destination allocation.
[in]nElement count.

Definition at line 135 of file tif_dir.c.

References setByteArray().

Referenced by _TIFFVSetField(), setExtraSamples(), setShortArrayWithCount(), and TIFFReadDirectory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setByteArray()

static void setByteArray ( TIFF *  tif,
void **  vpp,
const void *  vp,
size_t  nmemb,
size_t  elem_size 
)
static

Discard an old allocation and copy a replacement byte product.

Detaches and clears *vpp before checking/copying, and frees the old allocation only after the copy, so the source may alias it. With a non-NULL source, checks the product silently through _TIFFMultiplySSize(NULL, ..., NULL) and allocates only a positive valid result. Failure leaves *vpp NULL and does not preserve old contents. An allocator limit may report a diagnostic, but other size/allocation failures have no direct diagnostic. The replacement uses the matching _TIFFfreeExt() context.

Parameters
[in,out]tifMatching live accounting handle, or NULL.
[in,out]vppNon-NULL owner slot for a compatible allocation, or a NULL allocation.
[in]vpReadable source, or NULL to clear; may point into the old allocation.
[in]nmembCount representable by tmsize_t for the checked product.
[in]elem_sizeElement byte size representable by tmsize_t.

Definition at line 86 of file tif_dir.c.

References _TIFFfreeExt(), _TIFFmallocExt(), _TIFFmemcpy(), and _TIFFMultiplySSize().

Referenced by _TIFFsetByteArray(), _TIFFsetByteArrayExt(), _TIFFsetDoubleArray(), _TIFFsetDoubleArrayExt(), _TIFFsetFloatArray(), _TIFFsetFloatArrayExt(), _TIFFsetLong8Array(), _TIFFsetLongArray(), _TIFFsetLongArrayExt(), _TIFFsetNString(), _TIFFsetShortArray(), _TIFFsetShortArrayExt(), and _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDoubleArrayOneValue()

static void setDoubleArrayOneValue ( TIFF *  tif,
double **  vpp,
double  value,
size_t  nmemb 
)
static

Replace an owned double array with one repeated value.

Frees the previous allocation before attempting the new one. The size multiplication is not overflow-checked here: callers must satisfy the representability precondition. Zero count or allocation failure leaves *vpp NULL and discards old data. Returns no status; only allocator policy diagnostics may be emitted. Release the replacement with the matching _TIFFfreeExt() context.

Parameters
[in,out]tifMatching live accounting handle, or NULL.
[in,out]vppNon-NULL owner slot for a matching double array or NULL.
[in]valueValue to assign to every new element.
[in]nmembElement count; its conversion and byte product must fit tmsize_t.

Definition at line 208 of file tif_dir.c.

References _TIFFfreeExt(), _TIFFmallocExt(), and _TIFFMultiplySSize().

Referenced by _TIFFVSetField().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setShortArrayWithCount()

static int setShortArrayWithCount ( TIFF *  tif,
uint16_t **  wpp,
uint32_t *  countp,
const uint16_t *  wp,
uint32_t  n 
)
static

Install a short array together with the number of elements it holds.

The count is the only record the library keeps of the length of the array, so it is written here and nowhere else, and is cleared whenever the array is not installed.

Parameters
[in,out]tifDirectory handle owning the allocation.
[in,out]wppOwner slot for the array.
[out]countpRecorded length that belongs to wpp.
[in]wpReadable source of n entries.
[in]nNumber of entries to copy.
Returns
Nonzero on success, zero if the array could not be allocated.

Definition at line 241 of file tif_dir.c.

References _TIFFsetShortArrayExt().

Referenced by setColorMap(), and setTransferFunction().

Here is the call graph for this function:
Here is the caller graph for this function: