Skip to content

Photoshop PSD errors with Truncated File Read  #7482

@kporangehat

Description

@kporangehat

What did you do?

Tried to open a Photoshop psd file that loads fine in Photoshop.

This issue came up as I'm processing multiple Photoshop psd files at a time on a project. Some files work fine, others do not. All of the files open fine in Photoshop 2023.

Ultimately for this purpose I'm just looking to get the dimensions of the file and confirm the format. But in the future would like to actually be doing more processing on these files.

What did you expect to happen?

I expected the file to be opened.

What actually happened?

The code errors with OSError: Truncated File Read despite using the ImageFile.LOAD_TRUNCATED_IMAGES = True option.

This same result happens whether opening from a file path or loading bytes and opening from there. I tried several methods recommended in previous Github issue submissions.

What are your OS, Python and Pillow versions?

  • OS: MacOS Sonoma 14.0 (23A344)
  • Python: 3.9.17
  • Pillow: 10.1.0
python Python 3.9.17 (main, Aug 18 2023, 13:18:41) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from PIL import ImageFile, Image >>> ImageFile.LOAD_TRUNCATED_IMAGES = True >>> psd_file = "/Users/kp/dev/pil_psd_test/file.psd" >>> psd = Image.open(fp=psd_file) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/Image.py", line 3289, in open im = _open_core( File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/Image.py", line 3270, in _open_core im = factory(fp, filename) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/ImageFile.py", line 117, in __init__ self._open() File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 127, in _open self.layers = _layerinfo(_layer_data, size) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 224, in _layerinfo length = i32(read(4)) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 168, in read return ImageFile._safe_read(fp, size) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/ImageFile.py", line 571, in _safe_read raise OSError(msg) OSError: Truncated File Read >>> from io import BytesIO >>> with open(psd_file, 'rb') as fp: ... image_data = fp.read() ... bio = BytesIO(image_data) ... with Image.open(bio) as fo: ... try: ... fo.load() ... except OSError as e: ... pass ... img = fo.convert('RGB') ... Traceback (most recent call last): File "<stdin>", line 4, in <module> File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/Image.py", line 3284, in open im = _open_core(fp, filename, prefix, formats) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/Image.py", line 3270, in _open_core im = factory(fp, filename) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/ImageFile.py", line 117, in __init__ self._open() File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 127, in _open self.layers = _layerinfo(_layer_data, size) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 224, in _layerinfo length = i32(read(4)) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/PsdImagePlugin.py", line 168, in read return ImageFile._safe_read(fp, size) File "/Users/kp/dev/pil_psd_test/.venv/lib/python3.9/site-packages/PIL/ImageFile.py", line 571, in _safe_read raise OSError(msg) OSError: Truncated File Read

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions