• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 1988-1997 Sam Leffler
3  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Sam Leffler and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Sam Leffler and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 #ifndef _TIFFIOP_
26 #define _TIFFIOP_
27 /*
28  * ``Library-private'' definitions.
29  */
30 
31 #include "tiffconf.h"
32 
33 #ifdef HAVE_FCNTL_H
34 #include <fcntl.h>
35 #endif
36 
37 #ifdef HAVE_SYS_TYPES_H
38 #include <sys/types.h>
39 #endif
40 
41 #include <string.h>
42 
43 #ifdef HAVE_ASSERT_H
44 #include <assert.h>
45 #else
46 #define assert(x)
47 #endif
48 
49 #include "tif_hash_set.h"
50 #include "tiffio.h"
51 
52 #include "tif_dir.h"
53 
54 #include <limits.h>
55 
56 #ifndef STRIP_SIZE_DEFAULT
57 #define STRIP_SIZE_DEFAULT 8192
58 #endif
59 
60 #ifndef TIFF_MAX_DIR_COUNT
61 #define TIFF_MAX_DIR_COUNT 1048576
62 #endif
63 
64 #define TIFF_NON_EXISTENT_DIR_NUMBER UINT_MAX
65 
66 #define streq(a, b) (strcmp(a, b) == 0)
67 #define strneq(a, b, n) (strncmp(a, b, n) == 0)
68 
69 #ifndef TRUE
70 #define TRUE 1
71 #define FALSE 0
72 #endif
73 
74 typedef struct client_info
75 {
76     struct client_info *next;
77     void *data;
78     char *name;
79 } TIFFClientInfoLink;
80 
81 /*
82  * Typedefs for ``method pointers'' used internally.
83  * these are deprecated and provided only for backwards compatibility.
84  */
85 typedef unsigned char tidataval_t; /* internal image data value type */
86 typedef tidataval_t *tidata_t;     /* reference to internal image data */
87 
88 typedef void (*TIFFVoidMethod)(TIFF *);
89 typedef int (*TIFFBoolMethod)(TIFF *);
90 typedef int (*TIFFPreMethod)(TIFF *, uint16_t);
91 typedef int (*TIFFCodeMethod)(TIFF *tif, uint8_t *buf, tmsize_t size,
92                               uint16_t sample);
93 typedef int (*TIFFSeekMethod)(TIFF *, uint32_t);
94 typedef void (*TIFFPostMethod)(TIFF *tif, uint8_t *buf, tmsize_t size);
95 typedef uint32_t (*TIFFStripMethod)(TIFF *, uint32_t);
96 typedef void (*TIFFTileMethod)(TIFF *, uint32_t *, uint32_t *);
97 
98 struct TIFFOffsetAndDirNumber
99 {
100     uint64_t offset;
101     tdir_t dirNumber;
102 };
103 typedef struct TIFFOffsetAndDirNumber TIFFOffsetAndDirNumber;
104 
105 struct tiff
106 {
107     char *tif_name; /* name of open file */
108     int tif_fd;     /* open file descriptor */
109     int tif_mode;   /* open mode (O_*) */
110     uint32_t tif_flags;
111 #define TIFF_FILLORDER 0x00003U   /* natural bit fill order for machine */
112 #define TIFF_DIRTYHEADER 0x00004U /* header must be written on close */
113 #define TIFF_DIRTYDIRECT 0x00008U /* current directory must be written */
114 #define TIFF_BUFFERSETUP 0x00010U /* data buffers setup */
115 #define TIFF_CODERSETUP 0x00020U  /* encoder/decoder setup done */
116 #define TIFF_BEENWRITING 0x00040U /* written 1+ scanlines to file */
117 #define TIFF_SWAB 0x00080U        /* byte swap file information */
118 #define TIFF_NOBITREV 0x00100U    /* inhibit bit reversal logic */
119 #define TIFF_MYBUFFER 0x00200U    /* my raw data buffer; free on close */
120 #define TIFF_ISTILED 0x00400U     /* file is tile, not strip- based */
121 #define TIFF_MAPPED 0x00800U      /* file is mapped into memory */
122 #define TIFF_POSTENCODE 0x01000U  /* need call to postencode routine */
123 #define TIFF_INSUBIFD 0x02000U    /* currently writing a subifd */
124 #define TIFF_UPSAMPLED 0x04000U   /* library is doing data up-sampling */
125 #define TIFF_STRIPCHOP 0x08000U   /* enable strip chopping support */
126 #define TIFF_HEADERONLY                                                        \
127     0x10000U /* read header only, do not process the first directory */
128 #define TIFF_NOREADRAW                                                         \
129     0x20000U /* skip reading of raw uncompressed image data */
130 #define TIFF_INCUSTOMIFD 0x40000U /* currently writing a custom IFD */
131 #define TIFF_BIGTIFF 0x80000U     /* read/write bigtiff */
132 #define TIFF_BUF4WRITE 0x100000U  /* rawcc bytes are for writing */
133 #define TIFF_DIRTYSTRIP 0x200000U /* stripoffsets/stripbytecount dirty*/
134 #define TIFF_PERSAMPLE 0x400000U  /* get/set per sample tags as arrays */
135 #define TIFF_BUFFERMMAP                                                        \
136     0x800000U /* read buffer (tif_rawdata) points into mmap() memory */
137 #define TIFF_DEFERSTRILELOAD                                                   \
138     0x1000000U /* defer strip/tile offset/bytecount array loading. */
139 #define TIFF_LAZYSTRILELOAD                                                    \
140     0x2000000U /* lazy/ondemand loading of strip/tile offset/bytecount values. \
141                   Only used if TIFF_DEFERSTRILELOAD is set and in read-only    \
142                   mode */
143 #define TIFF_CHOPPEDUPARRAYS                                                   \
144     0x4000000U /* set when allocChoppedUpStripArrays() has modified strip      \
145                   array */
146     uint64_t tif_diroff;      /* file offset of current directory */
147     uint64_t tif_nextdiroff;  /* file offset of following directory */
148     uint64_t tif_lastdiroff;  /* file offset of last directory written so far */
149     uint64_t *tif_dirlistoff; /* list of offsets to already seen directories to
150                                  prevent IFD looping */
151     TIFFHashSet *tif_map_dir_offset_to_number;
152     TIFFHashSet *tif_map_dir_number_to_offset;
153     tdir_t tif_dirnumber;  /* number of already seen directories */
154     TIFFDirectory tif_dir; /* internal rep of current directory */
155     TIFFDirectory
156         tif_customdir; /* custom IFDs are separated from the main ones */
157     union
158     {
159         TIFFHeaderCommon common;
160         TIFFHeaderClassic classic;
161         TIFFHeaderBig big;
162     } tif_header;
163     uint16_t tif_header_size;  /* file's header block and its length */
164     uint32_t tif_row;          /* current scanline */
165     tdir_t tif_curdir;         /* current directory (index) */
166     uint32_t tif_curstrip;     /* current strip for read/write */
167     uint64_t tif_curoff;       /* current offset for read/write */
168     uint64_t tif_lastvalidoff; /* last valid offset allowed for rewrite in
169                                   place. Used only by TIFFAppendToStrip() */
170     uint64_t tif_dataoff;      /* current offset for writing dir */
171     /* SubIFD support */
172     uint16_t tif_nsubifd;   /* remaining subifds to write */
173     uint64_t tif_subifdoff; /* offset for patching SubIFD link */
174     /* tiling support */
175     uint32_t tif_col;      /* current column (offset by row too) */
176     uint32_t tif_curtile;  /* current tile for read/write */
177     tmsize_t tif_tilesize; /* # of bytes in a tile */
178     /* compression scheme hooks */
179     int tif_decodestatus;
180     TIFFBoolMethod tif_fixuptags;   /* called in TIFFReadDirectory */
181     TIFFBoolMethod tif_setupdecode; /* called once before predecode */
182     TIFFPreMethod tif_predecode;    /* pre- row/strip/tile decoding */
183     TIFFBoolMethod tif_setupencode; /* called once before preencode */
184     int tif_encodestatus;
185     TIFFPreMethod tif_preencode;      /* pre- row/strip/tile encoding */
186     TIFFBoolMethod tif_postencode;    /* post- row/strip/tile encoding */
187     TIFFCodeMethod tif_decoderow;     /* scanline decoding routine */
188     TIFFCodeMethod tif_encoderow;     /* scanline encoding routine */
189     TIFFCodeMethod tif_decodestrip;   /* strip decoding routine */
190     TIFFCodeMethod tif_encodestrip;   /* strip encoding routine */
191     TIFFCodeMethod tif_decodetile;    /* tile decoding routine */
192     TIFFCodeMethod tif_encodetile;    /* tile encoding routine */
193     TIFFVoidMethod tif_close;         /* cleanup-on-close routine */
194     TIFFSeekMethod tif_seek;          /* position within a strip routine */
195     TIFFVoidMethod tif_cleanup;       /* cleanup state routine */
196     TIFFStripMethod tif_defstripsize; /* calculate/constrain strip size */
197     TIFFTileMethod tif_deftilesize;   /* calculate/constrain tile size */
198     uint8_t *tif_data;                /* compression scheme private data */
199     /* input/output buffering */
200     tmsize_t tif_scanlinesize;  /* # of bytes in a scanline */
201     tmsize_t tif_scanlineskew;  /* scanline skew for reading strips */
202     uint8_t *tif_rawdata;       /* raw data buffer */
203     tmsize_t tif_rawdatasize;   /* # of bytes in raw data buffer */
204     tmsize_t tif_rawdataoff;    /* rawdata offset within strip */
205     tmsize_t tif_rawdataloaded; /* amount of data in rawdata */
206     uint8_t *tif_rawcp;         /* current spot in raw buffer */
207     tmsize_t tif_rawcc;         /* bytes unread from raw buffer */
208     /* memory-mapped file support */
209     uint8_t *tif_base; /* base of mapped file */
210     tmsize_t tif_size; /* size of mapped file region (bytes, thus tmsize_t) */
211     TIFFMapFileProc tif_mapproc;     /* map file method */
212     TIFFUnmapFileProc tif_unmapproc; /* unmap file method */
213     /* input/output callback methods */
214     thandle_t tif_clientdata;        /* callback parameter */
215     TIFFReadWriteProc tif_readproc;  /* read method */
216     TIFFReadWriteProc tif_writeproc; /* write method */
217     TIFFSeekProc tif_seekproc;       /* lseek method */
218     TIFFCloseProc tif_closeproc;     /* close method */
219     TIFFSizeProc tif_sizeproc;       /* filesize method */
220     /* post-decoding support */
221     TIFFPostMethod tif_postdecode; /* post decoding routine */
222     /* tag support */
223     TIFFField **tif_fields;          /* sorted table of registered tags */
224     size_t tif_nfields;              /* # entries in registered tag table */
225     const TIFFField *tif_foundfield; /* cached pointer to already found tag */
226     TIFFTagMethods tif_tagmethods;   /* tag get/set/print routines */
227     TIFFClientInfoLink *tif_clientinfo; /* extra client information. */
228     /* Backward compatibility stuff. We need these two fields for
229      * setting up an old tag extension scheme. */
230     TIFFFieldArray *tif_fieldscompat;
231     size_t tif_nfieldscompat;
232     /* Error handler support */
233     TIFFErrorHandlerExtR tif_errorhandler;
234     void *tif_errorhandler_user_data;
235     TIFFErrorHandlerExtR tif_warnhandler;
236     void *tif_warnhandler_user_data;
237     tmsize_t tif_max_single_mem_alloc; /* in bytes. 0 for unlimited */
238 };
239 
240 struct TIFFOpenOptions
241 {
242     TIFFErrorHandlerExtR errorhandler; /* may be NULL */
243     void *errorhandler_user_data;      /* may be NULL */
244     TIFFErrorHandlerExtR warnhandler;  /* may be NULL */
245     void *warnhandler_user_data;       /* may be NULL */
246     tmsize_t max_single_mem_alloc;     /* in bytes. 0 for unlimited */
247 };
248 
249 #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */
250 
251 #define isTiled(tif) (((tif)->tif_flags & TIFF_ISTILED) != 0)
252 #define isMapped(tif) (((tif)->tif_flags & TIFF_MAPPED) != 0)
253 #define isFillOrder(tif, o) (((tif)->tif_flags & (o)) != 0)
254 #define isUpSampled(tif) (((tif)->tif_flags & TIFF_UPSAMPLED) != 0)
255 #define TIFFReadFile(tif, buf, size)                                           \
256     ((*(tif)->tif_readproc)((tif)->tif_clientdata, (buf), (size)))
257 #define TIFFWriteFile(tif, buf, size)                                          \
258     ((*(tif)->tif_writeproc)((tif)->tif_clientdata, (buf), (size)))
259 #define TIFFSeekFile(tif, off, whence)                                         \
260     ((*(tif)->tif_seekproc)((tif)->tif_clientdata, (off), (whence)))
261 #define TIFFCloseFile(tif) ((*(tif)->tif_closeproc)((tif)->tif_clientdata))
262 #define TIFFGetFileSize(tif) ((*(tif)->tif_sizeproc)((tif)->tif_clientdata))
263 #define TIFFMapFileContents(tif, paddr, psize)                                 \
264     ((*(tif)->tif_mapproc)((tif)->tif_clientdata, (paddr), (psize)))
265 #define TIFFUnmapFileContents(tif, addr, size)                                 \
266     ((*(tif)->tif_unmapproc)((tif)->tif_clientdata, (addr), (size)))
267 
268 /*
269  * Default Read/Seek/Write definitions.
270  */
271 #ifndef ReadOK
272 #define ReadOK(tif, buf, size) (TIFFReadFile((tif), (buf), (size)) == (size))
273 #endif
274 #ifndef SeekOK
275 #define SeekOK(tif, off) _TIFFSeekOK(tif, off)
276 #endif
277 #ifndef WriteOK
278 #define WriteOK(tif, buf, size) (TIFFWriteFile((tif), (buf), (size)) == (size))
279 #endif
280 
281 /* NB: the uint32_t casts are to silence certain ANSI-C compilers */
282 #define TIFFhowmany_32(x, y)                                                   \
283     (((uint32_t)x < (0xffffffff - (uint32_t)(y - 1)))                          \
284          ? ((((uint32_t)(x)) + (((uint32_t)(y)) - 1)) / ((uint32_t)(y)))       \
285          : 0U)
286 /* Variant of TIFFhowmany_32() that doesn't return 0 if x close to MAXUINT. */
287 /* Caution: TIFFhowmany_32_maxuint_compat(x,y)*y might overflow */
288 #define TIFFhowmany_32_maxuint_compat(x, y)                                    \
289     (((uint32_t)(x) / (uint32_t)(y)) +                                         \
290      ((((uint32_t)(x) % (uint32_t)(y)) != 0) ? 1 : 0))
291 #define TIFFhowmany8_32(x)                                                     \
292     (((x)&0x07) ? ((uint32_t)(x) >> 3) + 1 : (uint32_t)(x) >> 3)
293 #define TIFFroundup_32(x, y) (TIFFhowmany_32(x, y) * (y))
294 #define TIFFhowmany_64(x, y)                                                   \
295     ((((uint64_t)(x)) + (((uint64_t)(y)) - 1)) / ((uint64_t)(y)))
296 #define TIFFhowmany8_64(x)                                                     \
297     (((x)&0x07) ? ((uint64_t)(x) >> 3) + 1 : (uint64_t)(x) >> 3)
298 #define TIFFroundup_64(x, y) (TIFFhowmany_64(x, y) * (y))
299 
300 /* Safe multiply which returns zero if there is an *unsigned* integer overflow.
301  * This macro is not safe for *signed* integer types */
302 #define TIFFSafeMultiply(t, v, m)                                              \
303     ((((t)(m) != (t)0) && (((t)(((v) * (m)) / (m))) == (t)(v)))                \
304          ? (t)((v) * (m))                                                      \
305          : (t)0)
306 
307 #define TIFFmax(A, B) ((A) > (B) ? (A) : (B))
308 #define TIFFmin(A, B) ((A) < (B) ? (A) : (B))
309 
310 #define TIFFArrayCount(a) (sizeof(a) / sizeof((a)[0]))
311 
312 /*
313   Support for large files.
314 
315   Windows read/write APIs support only 'unsigned int' rather than 'size_t'.
316   Windows off_t is only 32-bit, even in 64-bit builds.
317 */
318 #if defined(HAVE_FSEEKO)
319 /*
320   Use fseeko() and ftello() if they are available since they use
321   'off_t' rather than 'long'.  It is wrong to use fseeko() and
322   ftello() only on systems with special LFS support since some systems
323   (e.g. FreeBSD) support a 64-bit off_t by default.
324 
325   For MinGW, __MSVCRT_VERSION__ must be at least 0x800 to expose these
326   interfaces. The MinGW compiler must support the requested version.  MinGW
327   does not distribute the CRT (it is supplied by Microsoft) so the correct CRT
328   must be available on the target computer in order for the program to run.
329 */
330 #if defined(HAVE_FSEEKO)
331 #define fseek(stream, offset, whence) fseeko(stream, offset, whence)
332 #define ftell(stream, offset, whence) ftello(stream, offset, whence)
333 #endif
334 #endif
335 #if defined(__WIN32__) && !(defined(_MSC_VER) && _MSC_VER < 1400) &&           \
336     !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800)
337 typedef unsigned int TIFFIOSize_t;
338 #define _TIFF_lseek_f(fildes, offset, whence)                                  \
339     _lseeki64(fildes, /* __int64 */ offset, whence)
340 /* #define _TIFF_tell_f(fildes) /\* __int64 *\/ _telli64(fildes) */
341 #define _TIFF_fseek_f(stream, offset, whence)                                  \
342     _fseeki64(stream, /* __int64 */ offset, whence)
343 #define _TIFF_fstat_f(fildes, stat_buff)                                       \
344     _fstati64(fildes, /* struct _stati64 */ stat_buff)
345 /* #define _TIFF_ftell_f(stream) /\* __int64 *\/ _ftelli64(stream) */
346 /* #define _TIFF_stat_f(path,stat_buff) _stati64(path,/\* struct _stati64 *\/
347  * stat_buff) */
348 #define _TIFF_stat_s struct _stati64
349 #define _TIFF_off_t __int64
350 #else
351 typedef size_t TIFFIOSize_t;
352 #define _TIFF_lseek_f(fildes, offset, whence) lseek(fildes, offset, whence)
353 /* #define _TIFF_tell_f(fildes) (_TIFF_lseek_f(fildes,0,SEEK_CUR)) */
354 #define _TIFF_fseek_f(stream, offset, whence) fseek(stream, offset, whence)
355 #define _TIFF_fstat_f(fildes, stat_buff) fstat(fildes, stat_buff)
356 /* #define _TIFF_ftell_f(stream) ftell(stream) */
357 /* #define _TIFF_stat_f(path,stat_buff) stat(path,stat_buff) */
358 #define _TIFF_stat_s struct stat
359 #define _TIFF_off_t off_t
360 #endif
361 
362 #if defined(__has_attribute) && defined(__clang__)
363 #if __has_attribute(no_sanitize)
364 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW                                  \
365     __attribute__((no_sanitize("unsigned-integer-overflow")))
366 #else
367 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
368 #endif
369 #else
370 #define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
371 #endif
372 
373 #if defined(__cplusplus)
374 extern "C"
375 {
376 #endif
377     extern int _TIFFgetMode(TIFFOpenOptions *opts, thandle_t clientdata,
378                             const char *mode, const char *module);
379     extern int _TIFFNoRowEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
380                                 uint16_t s);
381     extern int _TIFFNoStripEncode(TIFF *tif, uint8_t *pp, tmsize_t cc,
382                                   uint16_t s);
383     extern int _TIFFNoTileEncode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
384     extern int _TIFFNoRowDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
385                                 uint16_t s);
386     extern int _TIFFNoStripDecode(TIFF *tif, uint8_t *pp, tmsize_t cc,
387                                   uint16_t s);
388     extern int _TIFFNoTileDecode(TIFF *, uint8_t *pp, tmsize_t cc, uint16_t s);
389     extern void _TIFFNoPostDecode(TIFF *tif, uint8_t *buf, tmsize_t cc);
390     extern int _TIFFNoPreCode(TIFF *tif, uint16_t s);
391     extern int _TIFFNoSeek(TIFF *tif, uint32_t off);
392     extern void _TIFFSwab16BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
393     extern void _TIFFSwab24BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
394     extern void _TIFFSwab32BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
395     extern void _TIFFSwab64BitData(TIFF *tif, uint8_t *buf, tmsize_t cc);
396     extern int TIFFFlushData1(TIFF *tif);
397     extern int TIFFDefaultDirectory(TIFF *tif);
398     extern void _TIFFSetDefaultCompressionState(TIFF *tif);
399     extern int _TIFFRewriteField(TIFF *, uint16_t, TIFFDataType, tmsize_t,
400                                  void *);
401     extern int TIFFSetCompressionScheme(TIFF *tif, int scheme);
402     extern int TIFFSetDefaultCompressionState(TIFF *tif);
403     extern uint32_t _TIFFDefaultStripSize(TIFF *tif, uint32_t s);
404     extern void _TIFFDefaultTileSize(TIFF *tif, uint32_t *tw, uint32_t *th);
405 
406     extern void _TIFFsetByteArray(void **, const void *, uint32_t);
407     extern void _TIFFsetByteArrayExt(TIFF *, void **, const void *, uint32_t);
408     extern void _TIFFsetShortArray(uint16_t **, const uint16_t *, uint32_t);
409     extern void _TIFFsetShortArrayExt(TIFF *, uint16_t **, const uint16_t *,
410                                       uint32_t);
411     extern void _TIFFsetLongArray(uint32_t **, const uint32_t *, uint32_t);
412     extern void _TIFFsetLongArrayExt(TIFF *, uint32_t **, const uint32_t *,
413                                      uint32_t);
414     extern void _TIFFsetFloatArray(float **, const float *, uint32_t);
415     extern void _TIFFsetFloatArrayExt(TIFF *, float **, const float *,
416                                       uint32_t);
417     extern void _TIFFsetDoubleArray(double **, const double *, uint32_t);
418     extern void _TIFFsetDoubleArrayExt(TIFF *, double **, const double *,
419                                        uint32_t);
420 
421     extern void _TIFFprintAscii(FILE *, const char *);
422     extern void _TIFFprintAsciiTag(FILE *, const char *, const char *);
423 
424     extern TIFFErrorHandler _TIFFwarningHandler;
425     extern TIFFErrorHandler _TIFFerrorHandler;
426     extern TIFFErrorHandlerExt _TIFFwarningHandlerExt;
427     extern TIFFErrorHandlerExt _TIFFerrorHandlerExt;
428     void _TIFFErrorEarly(TIFFOpenOptions *opts, thandle_t clientdata,
429                          const char *module, const char *fmt, ...)
430         TIFF_ATTRIBUTE((__format__(__printf__, 4, 5)));
431 
432     extern uint32_t _TIFFMultiply32(TIFF *, uint32_t, uint32_t, const char *);
433     extern uint64_t _TIFFMultiply64(TIFF *, uint64_t, uint64_t, const char *);
434     extern tmsize_t _TIFFMultiplySSize(TIFF *, tmsize_t, tmsize_t,
435                                        const char *);
436     extern tmsize_t _TIFFCastUInt64ToSSize(TIFF *, uint64_t, const char *);
437     extern void *_TIFFCheckMalloc(TIFF *, tmsize_t, tmsize_t, const char *);
438     extern void *_TIFFCheckRealloc(TIFF *, void *, tmsize_t, tmsize_t,
439                                    const char *);
440 
441     extern double _TIFFUInt64ToDouble(uint64_t);
442     extern float _TIFFUInt64ToFloat(uint64_t);
443 
444     extern float _TIFFClampDoubleToFloat(double);
445     extern uint32_t _TIFFClampDoubleToUInt32(double);
446 
447     extern tmsize_t _TIFFReadEncodedStripAndAllocBuffer(TIFF *tif,
448                                                         uint32_t strip,
449                                                         void **buf,
450                                                         tmsize_t bufsizetoalloc,
451                                                         tmsize_t size_to_read);
452     extern tmsize_t _TIFFReadEncodedTileAndAllocBuffer(TIFF *tif, uint32_t tile,
453                                                        void **buf,
454                                                        tmsize_t bufsizetoalloc,
455                                                        tmsize_t size_to_read);
456     extern tmsize_t _TIFFReadTileAndAllocBuffer(TIFF *tif, void **buf,
457                                                 tmsize_t bufsizetoalloc,
458                                                 uint32_t x, uint32_t y,
459                                                 uint32_t z, uint16_t s);
460     extern int _TIFFSeekOK(TIFF *tif, toff_t off);
461 
462     extern int TIFFInitDumpMode(TIFF *, int);
463 #ifdef PACKBITS_SUPPORT
464     extern int TIFFInitPackBits(TIFF *, int);
465 #endif
466 #ifdef CCITT_SUPPORT
467     extern int TIFFInitCCITTRLE(TIFF *, int), TIFFInitCCITTRLEW(TIFF *, int);
468     extern int TIFFInitCCITTFax3(TIFF *, int), TIFFInitCCITTFax4(TIFF *, int);
469 #endif
470 #ifdef THUNDER_SUPPORT
471     extern int TIFFInitThunderScan(TIFF *, int);
472 #endif
473 #ifdef NEXT_SUPPORT
474     extern int TIFFInitNeXT(TIFF *, int);
475 #endif
476 #ifdef LZW_SUPPORT
477     extern int TIFFInitLZW(TIFF *, int);
478 #endif
479 #ifdef OJPEG_SUPPORT
480     extern int TIFFInitOJPEG(TIFF *, int);
481 #endif
482 #ifdef JPEG_SUPPORT
483     extern int TIFFInitJPEG(TIFF *, int);
484     extern int TIFFJPEGIsFullStripRequired(TIFF *);
485 #endif
486 #ifdef JBIG_SUPPORT
487     extern int TIFFInitJBIG(TIFF *, int);
488 #endif
489 #ifdef ZIP_SUPPORT
490     extern int TIFFInitZIP(TIFF *, int);
491 #endif
492 #ifdef PIXARLOG_SUPPORT
493     extern int TIFFInitPixarLog(TIFF *, int);
494 #endif
495 #ifdef LOGLUV_SUPPORT
496     extern int TIFFInitSGILog(TIFF *, int);
497 #endif
498 #ifdef LERC_SUPPORT
499     extern int TIFFInitLERC(TIFF *tif, int);
500 #endif
501 #ifdef LZMA_SUPPORT
502     extern int TIFFInitLZMA(TIFF *, int);
503 #endif
504 #ifdef ZSTD_SUPPORT
505     extern int TIFFInitZSTD(TIFF *, int);
506 #endif
507 #ifdef WEBP_SUPPORT
508     extern int TIFFInitWebP(TIFF *, int);
509 #endif
510     extern const TIFFCodec _TIFFBuiltinCODECS[];
511     extern void TIFFCIELab16ToXYZ(TIFFCIELabToRGB *, uint32_t l, int32_t a,
512                                   int32_t b, float *, float *, float *);
513 
514     extern void *_TIFFmallocExt(TIFF *tif, tmsize_t s);
515     extern void *_TIFFcallocExt(TIFF *tif, tmsize_t nmemb, tmsize_t siz);
516     extern void *_TIFFreallocExt(TIFF *tif, void *p, tmsize_t s);
517     extern void _TIFFfreeExt(TIFF *tif, void *p);
518 
519 #if defined(__cplusplus)
520 }
521 #endif
522 #endif /* _TIFFIOP_ */
523