2019.10.01 18:01 "[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

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);

> "