29#ifdef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
30#undef TIFF_DO_NOT_USE_NON_EXT_ALLOC_FUNCTIONS
107 int warn_about_unknown_tags)
114 void *errorhandler_user_data)
122 void *warnhandler_user_data)
142 const char *pszFunction,
146 "Memory allocation of %" PRIu64
147 " bytes is beyond the %" PRIu64
148 " byte limit defined in open options",
167 const char *pszFunction,
171 "Cumulated memory allocation of %" PRIu64
" + %" PRIu64
172 " bytes is beyond the %" PRIu64
173 " cumulated byte limit defined in open options",
193#define LEADING_AREA_TO_STORE_ALLOC_SIZE (2 * SIZEOF_SIZE_T)
218 memcpy(ptr, &s,
sizeof(s));
251 memcpy(ptr, &s,
sizeof(s));
277 memcpy(&oldSize, oldPtr,
sizeof(oldSize));
278 assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
295 memcpy(newPtr, &s,
sizeof(s));
307 memcpy(&oldSize, oldPtr,
sizeof(oldSize));
308 assert(oldSize <= tif->tif_cur_cumulated_mem_alloc);
322 seekproc, closeproc, sizeproc, mapproc, unmapproc,
333 static const char module[] = "TIFFClientOpenExt";
344 assert(
sizeof(uint8_t) == 1);
345 assert(
sizeof(int8_t) == 1);
346 assert(
sizeof(uint16_t) == 2);
347 assert(
sizeof(int16_t) == 2);
348 assert(
sizeof(uint32_t) == 4);
349 assert(
sizeof(int32_t) == 4);
350 assert(
sizeof(uint64_t) == 8);
351 assert(
sizeof(int64_t) == 8);
362 assert(n.a16 == 256);
373 name_len = strlen(name) + 1;
379 "%s: Memory allocation of %" PRIu64
380 " bytes is beyond the %" PRIu64
381 " byte limit defined in open options",
382 name, (uint64_t)size_to_alloc,
390 "%s: Memory allocation of %" PRIu64
391 " bytes is beyond the %" PRIu64
392 " cumulated byte limit defined in open options",
393 name, (uint64_t)size_to_alloc,
401 "%s: Out of memory (TIFF structure)", name);
405 tif->tif_name = (
char *)tif +
sizeof(
TIFF);
407 tif->tif_mode = m & ~(O_CREAT | O_TRUNC);
411 tif->tif_clientdata = clientdata;
412 tif->tif_readproc = readproc;
413 tif->tif_writeproc = writeproc;
414 tif->tif_seekproc = seekproc;
415 tif->tif_closeproc = closeproc;
416 tif->tif_sizeproc = sizeproc;
434 if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc)
437 "One of the client procedures is NULL pointer.");
452#ifdef STRIPCHOP_DEFAULT
453 if (m == O_RDONLY || m == O_RDWR)
512 for (cp = mode; *cp; cp++)
537 "H(ost) mode is deprecated. Since "
538 "libtiff 4.5.1, it is an alias of 'B' / "
539 "FILLORDER_MSB2LSB.");
549 tif->tif_flags &= ~TIFF_MAPPED;
557 tif->tif_flags &= ~TIFF_STRIPCHOP;
578#ifdef DEFER_STRILE_LOAD
591 if (tif->tif_mode == O_RDONLY)
600 tif->tif_header.common.tiff_magic =
603 tif->tif_header.common.tiff_magic =
610 tif->tif_header.classic.tiff_diroff = 0;
621 tif->tif_header.big.tiff_offsetsize = 8;
622 tif->tif_header.big.tiff_unused = 0;
623 tif->tif_header.big.tiff_diroff = 0;
642 if (!
WriteOK(tif, &tif_header_swapped,
654 tif->tif_lastdiroff = 0;
655 tif->tif_setdirectory_force_absolute =
FALSE;
658 tif->tif_curdircount = 0;
677 "Not a TIFF or MDI file, bad magic number %" PRIu16
683 "Not a TIFF file, bad magic number %" PRIu16
686 tif->tif_header.common.tiff_magic,
687 tif->tif_header.common.tiff_magic);
708 "Not a TIFF file, bad version number %" PRIu16
710 tif->tif_header.common.tiff_version,
711 tif->tif_header.common.tiff_version);
734 if (tif->tif_header.big.tiff_offsetsize != 8)
737 "Not a TIFF file, bad BigTIFF offsetsize %" PRIu16
739 tif->tif_header.big.tiff_offsetsize,
740 tif->tif_header.big.tiff_offsetsize);
743 if (tif->tif_header.big.tiff_unused != 0)
746 "Not a TIFF file, bad BigTIFF unused %" PRIu16
748 tif->tif_header.big.tiff_unused,
749 tif->tif_header.big.tiff_unused);
756 tif->tif_rawcp = tif->tif_rawdata = 0;
757 tif->tif_rawdatasize = 0;
758 tif->tif_rawdataoff = 0;
759 tif->tif_rawdataloaded = 0;
765 tif->tif_nextdiroff = tif->tif_header.classic.tiff_diroff;
767 tif->tif_nextdiroff = tif->tif_header.big.tiff_diroff;
779 assert((
toff_t)tif->tif_size == n);
782 tif->tif_flags &= ~TIFF_MAPPED;
822 tif->tif_mode = O_RDONLY;
842 const char *old_name = tif->
tif_name;
void _TIFFSetDefaultCompressionState(TIFF *tif)
Install fallback codec callbacks and reset raw-access flags.
int TIFFDefaultDirectory(TIFF *tif)
Install the image schema, default values, and core tag methods.
void _TIFFResetTifDirAndInitStrileCounters(TIFFDirectory *td)
Zero directory storage and initialise traversal sentinels.
int _tiffDummyMapProc(thandle_t fd, void **pbase, toff_t *psize)
Decline mapping when the client supplies no mapping implementation.
void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata, const char *module, const char *fmt,...)
Report an opening error before a complete TIFF handle is available.
int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata, const char *mode, const char *module)
Translate the leading open-mode characters into OS access flags.
void _tiffDummyUnmapProc(thandle_t fd, void *base, toff_t size)
Provide a no-op unmapper when the client omits one.
void _TIFFfreeExt(TIFF *tif, void *p)
Release a handle-aware allocation and its payload charge.
static void _TIFFEmitErrorAboveMaxCumulatedMemAlloc(TIFF *tif, const char *pszFunction, tmsize_t s)
Report a rejected cumulative allocation-policy check.
void * _TIFFreallocExt(TIFF *tif, void *p, tmsize_t s)
Resize a handle-aware block or release it for a nonpositive size.
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.
static void _TIFFEmitErrorAboveMaxSingleMemAlloc(TIFF *tif, const char *pszFunction, tmsize_t s)
Report a rejected single allocation-policy check.
#define LEADING_AREA_TO_STORE_ALLOC_SIZE
Reserve two size_t widths before a cumulatively tracked payload.
#define TIFF_NON_EXISTENT_DIR_NUMBER
Mark an unknown or nonexistent directory index.
#define isTiled(tif)
Test whether a handle uses tiled storage.
#define WriteOK(tif, buf, size)
Test whether one client write transfers the entire requested byte count.
#define isUpSampled(tif)
Test whether the codec reports upsampled output.
#define TIFF_MYBUFFER
Mark a raw buffer owned and released by the handle.
#define ReadOK(tif, buf, size)
Test whether one client read transfers the entire requested byte count.
#define TIFF_HEADERONLY
Request header-only opening without reading the first IFD.
#define TIFF_LAZYSTRILELOAD_ASKED
Record a lazy strip/tile loading request from the O open flag.
#define TIFFMapFileContents(tif, paddr, psize)
Invoke the handle's client mapping callback.
#define TIFF_STRIPCHOP
Enable internal chopping of a large uncompressed strip.
#define TIFF_DEFERSTRILELOAD
Defer loading strip/tile offset and byte-count arrays.
#define isFillOrder(tif, o)
Test whether selected bit-fill-order bits are present in a handle.
#define FALSE
Represent the legacy internal false value.
#define TIFFSeekFile(tif, off, whence)
Invoke the handle's client seek callback.
#define TIFF_MAPPED
Request or record memory-mapped file access.
#define TIFF_BIGTIFF
Mark the BigTIFF file format.
#define TIFF_SWAB
Request swapping multibyte file values to or from host order.
#define HOST_BIGENDIAN
Indicate native CPU byte order: 1 for big-endian, 0 for little-endian.
#define STRIPCHOP_DEFAULT
Define the default strip-chopping flag when strip chopping is enabled.
#define MDI_SUPPORT
Indicate support for Microsoft Document Imaging signatures when defined.
void TIFFSwabLong8(uint64_t *lp)
Reverse the byte order of one value.
void TIFFSwabShort(uint16_t *wp)
Reverse the byte order of one value.
void TIFFSwabLong(uint32_t *lp)
Reverse the byte order of one value.
void TIFFWarningExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a warning diagnostic to the configured handlers.
void TIFFErrorExtR(TIFF *tif, const char *module, const char *fmt,...)
Dispatch a error diagnostic to the configured handlers.
tdir_t TIFFCurrentDirectory(TIFF *tif)
Read the cached index of the current directory.
int TIFFReadDirectory(TIFF *tif)
Read and install the next image directory.
uint32_t TIFFCurrentTile(TIFF *tif)
Read the cached current tile index.
uint32_t TIFFCurrentRow(TIFF *tif)
Read the cached current scanline index.
uint32_t TIFFCurrentStrip(TIFF *tif)
Read the cached current strip index.
toff_t(* TIFFSeekProc)(thandle_t fd, toff_t off, int whence)
Change the current position of a client I/O resource.
int(* TIFFCloseProc)(thandle_t fd)
Release a client I/O resource or its adapter context.
void(* TIFFUnmapFileProc)(thandle_t fd, void *base, toff_t size)
Release a whole-file view supplied by a mapping callback.
toff_t(* TIFFSizeProc)(thandle_t fd)
Query the byte length of a client I/O resource.
tmsize_t(* TIFFReadWriteProc)(thandle_t fd, void *buf, tmsize_t size)
Transfer bytes at the current position of a client I/O resource.
int(* TIFFMapFileProc)(thandle_t fd, void **base, toff_t *size)
Provide a readable whole-file view of a client resource.
int TIFFGetMode(TIFF *tif)
Return the stored library access mode.
int TIFFFileno(TIFF *tif)
Return the handle's file-descriptor metadata.
TIFF * TIFFClientOpenExt(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc, TIFFOpenOptions *opts)
Initialise a TIFF handle using client-supplied I/O callbacks.
TIFF * TIFFClientOpen(const char *name, const char *mode, thandle_t clientdata, TIFFReadWriteProc readproc, TIFFReadWriteProc writeproc, TIFFSeekProc seekproc, TIFFCloseProc closeproc, TIFFSizeProc sizeproc, TIFFMapFileProc mapproc, TIFFUnmapFileProc unmapproc)
Initialise a TIFF handle using client-supplied I/O callbacks.
TIFFReadWriteProc TIFFGetReadProc(TIFF *tif)
Return the installed client read callback.
int TIFFSetFileno(TIFF *tif, int fd)
Replace descriptor metadata without changing client I/O routing.
TIFFCloseProc TIFFGetCloseProc(TIFF *tif)
Return the installed client close callback.
const char * TIFFFileName(TIFF *tif)
Return the handle's diagnostic filename.
TIFFSizeProc TIFFGetSizeProc(TIFF *tif)
Return the installed client file-size callback.
int TIFFSetMode(TIFF *tif, int mode)
Replace the stored library access mode without reopening the resource.
int TIFFIsMSB2LSB(TIFF *tif)
Test the selected data bit-fill-order flag.
int TIFFIsByteSwapped(TIFF *tif)
Test whether file values require byte swapping for this host.
TIFFMapFileProc TIFFGetMapFileProc(TIFF *tif)
Return the installed client mapping callback.
int TIFFIsTiled(TIFF *tif)
Test whether the current image uses tiles.
const char * TIFFSetFileName(TIFF *tif, const char *name)
Replace the diagnostic filename pointer without copying it.
void TIFFCleanup(TIFF *tif)
Release library state without invoking the client close callback.
TIFFSeekProc TIFFGetSeekProc(TIFF *tif)
Return the installed client seek callback.
int TIFFIsBigTIFF(TIFF *tif)
Test whether the handle uses the BigTIFF format.
thandle_t TIFFSetClientdata(TIFF *tif, thandle_t newvalue)
Replace the context passed to all client I/O callbacks.
TIFFUnmapFileProc TIFFGetUnmapFileProc(TIFF *tif)
Return the installed client unmapping callback.
int TIFFIsBigEndian(TIFF *tif)
Test whether the stored file signature is TIFF_BIGENDIAN.
int TIFFIsUpSampled(TIFF *tif)
Test whether the active codec supplies upsampled data.
TIFFReadWriteProc TIFFGetWriteProc(TIFF *tif)
Return the installed client write callback.
thandle_t TIFFClientdata(TIFF *tif)
Return the context passed to client I/O callbacks.
void _TIFFfree(void *p)
Release a block allocated by the public allocation family.
void * _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
Allocate a zero-filled array through the public allocator.
void _TIFFmemset(void *p, int v, tmsize_t c)
Fill a byte range with one repeated byte.
void * _TIFFmalloc(tmsize_t s)
Allocate an uninitialised block through the public allocator.
void _TIFFmemcpy(void *d, const void *s, tmsize_t c)
Copy a non-overlapping byte range.
void * _TIFFrealloc(void *p, tmsize_t s)
Resize a public-allocator block using platform realloc semantics.
void TIFFOpenOptionsSetWarningHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *warnhandler_user_data)
Set the per-handle warning callback for subsequent opens.
void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data)
Set the per-handle error callback for subsequent opens.
void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, tmsize_t max_cumulated_mem_alloc)
Set the cumulative checked allocation limit for subsequent opens.
void TIFFOpenOptionsSetWarnAboutUnknownTags(TIFFOpenOptions *opts, int warn_about_unknown_tags)
Select whether subsequent opens warn about unknown tags.
int(* TIFFErrorHandlerExtR)(TIFF *tif, void *user_data, const char *module, const char *fmt, va_list ap)
Handle a diagnostic using a per-handle borrowed context.
TIFFOpenOptions * TIFFOpenOptionsAlloc(void)
Allocate default options for opening a TIFF handle.
void TIFFOpenOptionsSetMaxSingleMemAlloc(TIFFOpenOptions *opts, tmsize_t max_single_mem_alloc)
Set the single checked allocation limit for subsequent opens.
void TIFFOpenOptionsFree(TIFFOpenOptions *opts)
Release an open-options object.
TIFF_SSIZE_T tmsize_t
Represent a signed memory or I/O size in bytes.
#define TIFF_TMSIZE_T_MAX
Define the largest positive size representable by tmsize_t.
#define TIFF_LITTLEENDIAN
Identify little-endian TIFF byte order (the bytes II).
#define MDI_LITTLEENDIAN
Microsoft Document Imaging signature bytes (EP) read on a little-endian host.
uint64_t toff_t
Represent an unsigned file byte offset independently of off_t.
#define MDI_BIGENDIAN
Microsoft Document Imaging signature bytes (EP) read on a big-endian host.
uint32_t tdir_t
Represent a zero-based directory index, rather than a file offset.
#define TIFF_VERSION_BIG
Identify the BigTIFF file format in a file header.
#define TIFF_VERSION_CLASSIC
Identify the classic TIFF file format in a file header.
void * thandle_t
Carry an opaque client I/O context through library callbacks.
#define TIFF_BIGENDIAN
Identify big-endian TIFF byte order (the bytes MM).
uint32_t td_row
Current scanline index; UINT32_MAX before traversal starts.
uint32_t td_curtile
Current tile index, or NOTILE.
uint32_t td_curstrip
Current strip index, or NOSTRIP.
Hold allocation limits and diagnostics used when opening a TIFF handle.
void * errorhandler_user_data
Borrowed error-callback context, or NULL.
tmsize_t max_cumulated_mem_alloc
Maximum tracked allocation total in bytes; zero means unlimited.
TIFFErrorHandlerExtR errorhandler
Optional per-handle error callback, or NULL.
int warn_about_unknown_tags
Nonzero to warn about unknown tags.
TIFFErrorHandlerExtR warnhandler
Optional per-handle warning callback, or NULL.
void * warnhandler_user_data
Borrowed warning-callback context, or NULL.
tmsize_t max_single_mem_alloc
Maximum individual allocation in bytes; zero means unlimited.
Hold private state for one open TIFF library instance.
TIFFReadWriteProc tif_readproc
Client read callback.
TIFFReadWriteProc tif_writeproc
Client write callback.
tmsize_t tif_max_single_mem_alloc
Single-allocation byte limit; zero means unlimited.
TIFFUnmapFileProc tif_unmapproc
Client callback releasing a mapped-file view.
TIFFSeekProc tif_seekproc
Client seek callback.
TIFFCloseProc tif_closeproc
Client I/O close callback.
thandle_t tif_clientdata
Client I/O context passed unchanged to the I/O callbacks.
char * tif_name
Current filename pointer; may refer to inline or client-supplied storage.
TIFFDirectory tif_dir
Inline representation of the current image directory.
tdir_t tif_curdir
Track the current or last-written directory index.
tmsize_t tif_cur_cumulated_mem_alloc
Current tracked allocation total in bytes.
int tif_fd
File-descriptor metadata; client I/O still uses tif_clientdata.
TIFFMapFileProc tif_mapproc
Client callback providing a mapped-file view.
TIFFHeaderUnion tif_header
Inline decoded classic TIFF or BigTIFF file header.
tmsize_t tif_max_cumulated_mem_alloc
Cumulative tracked-allocation byte limit; zero means unlimited.
uint32_t tif_flags
Bitmask combining the TIFF_* handle-state flags declared below.
int tif_mode
Current access mode using the O_* constants.
TIFFSizeProc tif_sizeproc
Client file-size callback.
Declare private library state, callbacks, and implementation helpers.