Added ImageSourceData to TAGS_V2 by radarhere · Pull Request #7053 · python-pillow/Pillow
In #7008, two images were reported to cause a RuntimeError. Testing on my machine, I found that this caused a segfault instead.
It turns out that this was due to an incorrect tag type being used for ImageSourceData.
Except then I found the RuntimeError, happening on 32-bit Windows.
E RuntimeError: Error setting from dictionary
C:\hostedtoolcache\windows\Python\3.7.9\x86\lib\site-packages\pillow-9.5.0.dev0-py3.7-win32.egg\PIL\Image.py:437: RuntimeError
---------------------------- Captured stderr call -----------------------------
_TIFFVSetField: C:\Users\runneradmin\AppData\Local\Temp\pytest-of-runneradmin\pytest-0\test_save_imagesourcedata0\temp.tif: Bad LONG8 or IFD8 value 1000052142389717520 for "EXIFIFDOffset" tag 34665 in ClassicTIFF. Tag won't be written to file.
When it states 'Bad LONG8 or IFD8 value 1000052142389717520 for "EXIFIFDOffset" tag 34665', that number wasn't the value being passed through for the EXIF IFD offset from Python. When we are about to pass the value through to libtiff in C, we cast it to UINT32.
| status = ImagingLibTiffSetField( | |
| &encoder->state, (ttag_t)key_int, (UINT32)PyLong_AsLong(value)); |
When libtiff is throwing the error, the variable is uint64_t. Changing UINT32 to uint64_t fixed the RunTimeError.