AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2019.10.01 18:01 "[Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.01 19:10 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Bob Friesenhahn
2019.11.03 18:13 "[Tiff] libtiff, breaking with release traditions", by Bob Friesenhahn
2019.11.03 22:52 "[Tiff] Libtiff 4.1.0 is released", by Bob Friesenhahn
2019.10.01 19:37 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Roger Leigh
2019.10.01 21:42 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Bob Friesenhahn
2019.10.01 21:57 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Olivier Paquet
2019.10.02 02:39 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 12:10 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 12:14 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Edward Lam
2019.10.10 12:38 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Olivier Paquet
2019.10.10 14:21 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 14:28 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 18:41 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Roger Leigh
2019.10.10 19:11 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Even Rouault
2019.10.10 19:40 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Bob Friesenhahn
2019.10.10 22:24 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 22:42 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Scott Ribe
2019.10.10 14:23 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 12:25 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Scott Ribe
2019.10.10 14:22 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.11 02:55 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Edward Lam
2019.10.02 12:29 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Edward Lam
2019.10.02 13:14 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.02 13:29 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Bob Friesenhahn
2019.10.10 10:28 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge
2019.10.10 11:28 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Edward Lam
2019.10.02 13:18 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by Bob Friesenhahn

2019.10.10 14:28 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge

In the grand scheme of things it cost very little, moving the decision logic to the open code might make more sense I'll agree.

D.

-----Original Message-----

From: Tiff [mailto:tiff-bounces@lists.osgeo.org] On Behalf Of Edward Lam

On 10/10/2019 8:10 AM, David C. Partridge wrote:

 > I like to propose that this be adopted into the official codebase :)

Do we really want to be calling GetVersion() on every single I/O call on Windows?

So the code now looks like (starting at line 58 of tif_unix.c):

#endif

#define TIFF_IO_MAX 2147483647U

typedef union fd_as_handle_union
{
        int fd;
        thandle_t h;
} fd_as_handle_union_t;

static tmsize_t
_tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
{
        fd_as_handle_union_t fdh;
        const size_t bytes_total = (size_t) size;
        size_t bytes_read;
        tmsize_t count = -1;
        if ((tmsize_t) bytes_total != size)
        {
                errno=EINVAL;
                return (tmsize_t) -1;
        }
#ifdef __WIN32__
        unsigned long limit = TIFF_IO_MAX;

        if (IsWindowsXP()) limit = 16777216UL;

#else
        const unsigned long limit = TIFF_IO_MAX;
#endif
        fdh.h = fd;
        for (bytes_read=0; bytes_read < bytes_total; bytes_read+=count)
        {
                char *buf_offset = (char *) buf+bytes_read;
                size_t io_size = bytes_total-bytes_read;
                if (io_size > limit)
                        io_size = limit;
                count=read(fdh.fd, buf_offset, (TIFFIOSize_t) io_size);
                if (count <= 0)
                        break;
        }
                if (count < 0)
                {
                        fprintf(stderr, "read() failed with errno %d\n", *_errno());
                        return (tmsize_t)-1;
                }
        return (tmsize_t) bytes_read;
}

static tmsize_t
_tiffWriteProc(thandle_t fd, void* buf, tmsize_t size)
{
        fd_as_handle_union_t fdh;
        const size_t bytes_total = (size_t) size;
        size_t bytes_written;
        tmsize_t count = -1;
        if ((tmsize_t) bytes_total != size)
        {
                errno=EINVAL;
                return (tmsize_t) -1;
        }
#ifdef __WIN32__
        unsigned long limit = TIFF_IO_MAX;

        if (IsWindowsXP()) limit = 16777216UL;

#else
        const unsigned long limit = TIFF_IO_MAX;
#endif

        fdh.h = fd;
        for (bytes_written=0; bytes_written < bytes_total; bytes_written+=count)
        {
                const char *buf_offset = (char *) buf+bytes_written;
                size_t io_size = bytes_total-bytes_written;
                if (io_size > limit)
                        io_size = limit;
                count=write(fdh.fd, buf_offset, (TIFFIOSize_t) io_size);

> "