TIFFFdOpen functions from tif_unix.c and tif_win32.c are not compatible
Summary
Since merge_requests/75, CMake builds (now using tif_win32.c
) and nmake builds (using tif_unix.c
) are incompatible wrt. the TIFFFdOpen
function. tif_win32.c::TIFFFdOpen
requires Windows file HANDLE, while tif_unix.c::TIFFFdOpen
requires C runtime fileno.
This causes failures in the Python Image Library when CMake builds of libtiff-4.1.0 are used. The following patch fixes/demonstrates the issue just for Pillow:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0285be0..a4addd90 100644
--- a/libtiff/tif_win32.c
+++ b/libtiff/tif_win32.c
@@ -226,6 +226,7 @@ TIFF*
TIFFFdOpen(int ifd, const char* name, const char* mode)
{
TIFF* tif;
+ thandle_t clientdata;
int fSuppressMap;
int m;
fSuppressMap=0;
@@ -237,7 +238,10 @@ TIFFFdOpen(int ifd, const char* name, const char* mode)
break;
}
}
- tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */
+
+ clientdata = (thandle_t)_get_osfhandle(ifd);
+
+ tif = TIFFClientOpen(name, mode, clientdata,
_tiffReadProc, _tiffWriteProc,
_tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
fSuppressMap ? _tiffDummyMapProc : _tiffMapProc,
Version
tiff-4.1.0
Steps to reproduce
Build libtiff 4.1.0 using CMake, then build and test Pillow-6.2.1
Platform
Windows 10 latest, Visual Studio 2017 latest