Skip to content

PIL 12.1.1 Pillow cannot reliably reload YCbCr TIFFs that it has generated itself #9770

Description

@ProfessorHubble
PIL 1Test_01.py --wdir
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File ~/Software/python/Bildverarbeitung_tensorflow_env/TIFF-Test_01.py:18
     15 img.save("test.tif", compression="raw", tiffinfo={530: (1, 1)}) # 4:4:4
     17 img2 = Image.open("test.tif")
---> 18 img2.load()
     20 print("OK")

File ~/anaconda3/envs/tensorflow/lib/python3.10/site-packages/PIL/TiffImagePlugin.py:1303, in TiffImageFile.load(self)
   1301 if self.tile and self.use_load_libtiff:
   1302     return self._load_libtiff()
-> 1303 return super().load()

File ~/anaconda3/envs/tensorflow/lib/python3.10/site-packages/PIL/ImageFile.py:403, in ImageFile.load(self)
    398     else:
    399         msg = (
    400             "image file is truncated "
    401             f"({len(b)} bytes not processed)"
    402         )
--> 403         raise OSError(msg)
    405 b = b + s
    406 n, err_code = decoder.decode(b)

OSError: image file is truncated (0 bytes not processed)

2.1.1 Pillow cannot reliably reload YCbCr TIFFs that it has generated itself.

What did you do?

Testprogram:

import numpy as np
from PIL import Image
arr = np.zeros((64, 64, 3), dtype=np.uint8)
arr[:, :, 0] = 100
arr[:, :, 1] = 128
arr[:, :, 2] = 128

img = Image.fromarray(arr, "YCbCr")
img.save("test.tif", compression="raw")

img2 = Image.open("test.tif")
img2.load()

print("OK")

What did you expect to happen?

What actually happened?

What are your OS, Python and Pillow versions?

  • OS: ubuntu 22.04 LTS
  • Python: 3.10.12
  • Pillow: 12.1.1

Testprogram crashing:

Test_01.py --wdir
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File ~/Software/python/Bildverarbeitung_tensorflow_env/TIFF-Test_01.py:18
     15 img.save("test.tif", compression="raw", tiffinfo={530: (1, 1)}) # 4:4:4
     17 img2 = Image.open("test.tif")
---> 18 img2.load()
     20 print("OK")

File ~/anaconda3/envs/tensorflow/lib/python3.10/site-packages/PIL/TiffImagePlugin.py:1303, in TiffImageFile.load(self)
   1301 if self.tile and self.use_load_libtiff:
   1302     return self._load_libtiff()
-> 1303 return super().load()

File ~/anaconda3/envs/tensorflow/lib/python3.10/site-packages/PIL/ImageFile.py:403, in ImageFile.load(self)
    398     else:
    399         msg = (
    400             "image file is truncated "
    401             f"({len(b)} bytes not processed)"
    402         )
--> 403         raise OSError(msg)
    405 b = b + s
    406 n, err_code = decoder.decode(b)

OSError: image file is truncated (0 bytes not processed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions