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.02 02:39 "Re: [Tiff] TIFF_IO_MAX too large for Windows XP", by David C. Partridge

Sadly it can't all be done with the pre-processor, you need a runtime call as well

But based on the assumption that the limit is USRHT_MAX in Windows XP. If the real limit is greater you just need to change USRHT_MAX in the following to the appropriate value.

just before the #define TIFF_IO_MAX 2147483647U

add the lines:

#ifdef __WIN32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL IsWindowsXP()
{
        DWORD version = GetVersion();
        DWORD major = (DWORD)(LOBYTE(LOWORD(version)));
        DWORD minor = (DWORD)(HIBYTE(LOWORD(version)));
        return ((major == 5) && (minor >= 1)); // 5.1 is WIN Xp 5.2 is XP x64
};

#endif

Then:

_tiffReadProc and _tiffWriteProc change to read like:

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 = USHRT_MAX;
#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 = USHRT_MAX;
#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);
                if (count <= 0)
                        break;
        }
                if (count < 0)
                {
                        fprintf(stderr, "write() failed with errno %d\n", *_errno());
                        return (tmsize_t)-1;
                }
        return (tmsize_t) bytes_written;
        /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */
}

David

-----Original Message-----
From: Tiff [mailto:tiff-bounces@lists.osgeo.org] On Behalf Of Roger Leigh
Sent: 01 October 2019 20:38
To: tiff@lists.osgeo.org
Subje