Skip to content

Reachable assert in FtexImagePlugin.py #9809

Description

@nevercodecorrect

Hi,

What did you do?

In testing the Image.open(), I found a minor issue with a reachable assert that is inconsistent with the code's primary use of raising an error. I am wondering whether this is intended.

What did you expect to happen?

Pillow should reject the unsupported/malformed FTEX file using its normal image-format error handling, such as raising UnidentifiedImageError.
An explicit check raising SyntaxError may be appropriate here because Image.open() treats that as a plugin rejecting the input:

if format_count != 1:
       msg = f"Unsupported FTEX format count: {format_count}"
       raise SyntaxError(msg)

What actually happened?

FtexImagePlugin._open() raises an uncaught AssertionError:

  Traceback (most recent call last):
    File "repro.py", line 9, in <module>
      Image.open(io.BytesIO(data))
    File ".../PIL/Image.py", line 3693, in open
      im = _open_core(
    File ".../PIL/Image.py", line 3673, in _open_core
      im = factory(fp, filename)
    File ".../PIL/ImageFile.py", line 150, in __init__
      self._open()
    File ".../PIL/FtexImagePlugin.py", line 85, in _open
      assert format_count == 1
  AssertionError

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04.5
  • Python: 3.10.12
  • Pillow: 12.2.0
 --------------------------------------------------------------------
  Pillow 12.2.0
  Python 3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
  --------------------------------------------------------------------
  Python executable is /usr/bin/python3
  System Python files loaded from /usr
  --------------------------------------------------------------------
  Python Pillow modules loaded from /home/xxxx/.local/lib/python3.10/site-packages/PIL
  Binary Pillow modules loaded from /home/xxxx/.local/lib/python3.10/site-packages/PIL
  --------------------------------------------------------------------
  --- PIL CORE support ok, compiled for 12.2.0
  *** TKINTER support not installed
  --- FREETYPE2 support ok, loaded 2.14.3
  --- LITTLECMS2 support ok, loaded 2.18
  --- WEBP support ok, loaded 1.6.0
  --- AVIF support ok, loaded 1.4.1
  --- JPEG support ok, compiled for libjpeg-turbo 3.1.4.1
  --- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
  --- ZLIB (PNG/ZIP) support ok, loaded 1.2.11, compiled for zlib-ng 2.3.3
  --- LIBTIFF support ok, loaded 4.7.1
  --- RAQM (Bidirectional Text) support ok, loaded 0.10.3,
      fribidi 1.0.8, harfbuzz 13.2.1
  *** LIBIMAGEQUANT support not installed
  --- XCB support ok
  --------------------------------------------------------------------
import io
import struct
from PIL import Image
# FTEX header:
# magic, version, width, height, mipmap_count, format_count,
# compression format, data offset
data = struct.pack(
      "<4s7i",
      b"FTEX",
      1,
      1,
      1,
      1,
      2,  # The plugin only supports format_count == 1
      0,
      0,
  )
Image.open(io.BytesIO(data))

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