Skip to content

bigtiff offset overflow #9811

Description

@nevercodecorrect

What did you do?

I opened a malformed 38-byte BigTIFF whose first out-of-line tag data offset (0x97006b0097009797) exceeds the platform's signed seek range (sys.maxsize on 64-bit).

What did you expect to happen?

Pillow should reject or skip the malformed TIFF directory through its normal corrupt-image path. ImageFileDirectory_v2.load() already catches OSError around this loop, warns, and returns. A raw integer-conversion exception should not escape the public Image.open() call.

What actually happened?

ImageFileDirectory_v2.load() reads a 64-bit out-of-line data offset and passes it straight to fp.seek(offset). Because the offset exceeds C ssize_t, BytesIO.seek() raises OverflowError, which is a subclass of ArithmeticError
(not OSError), So the surrounding except OSError handler does not catch it:

Traceback (most recent call last):
  File "repro.py", line 8, in <module>
    Image.open(io.BytesIO(data))
  File ".../PIL/Image.py", line 3697, in open
    im = _open_core(
  File ".../PIL/Image.py", line 3677, in _open_core
    im = factory(fp, filename)
  File ".../PIL/TiffImagePlugin.py", line 1176, in __init__
    super().__init__(fp, filename)
  File ".../PIL/ImageFile.py", line 150, in __init__
    self._open()
  File ".../PIL/TiffImagePlugin.py", line 1201, in _open
    self._seek(0)
  File ".../PIL/TiffImagePlugin.py", line 1249, in _seek
    self.tag_v2.load(self.fp)
  File ".../PIL/TiffImagePlugin.py", line 917, in load
    fp.seek(offset)
OverflowError: Python int too large to convert to C ssize_t

The relevant code in ImageFileDirectory_v2.load() is:

if size > (8 if self._bigtiff else 4):
    here = fp.tell()
    (offset,) = self._unpack("Q" if self._bigtiff else "L", data)
    ...
    fp.seek(offset)

wrapped by except OSError as msg: warnings.warn(str(msg)); return.

These TIFF bytes can raise an unexpected OverflowError. For a caller that whitelists those exceptions, it becomes an uncaught exception. The failure is in the pure-Python side so i assume it could not be a vulnerability.

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04.5 LTS, x86_64
  • Python: 3.10.12
  • Pillow: 12.3.0
--------------------------------------------------------------------
Pillow 12.3.0
Python 3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0]
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.14.3
--- LITTLECMS2 support ok, loaded 2.19
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.4.2
--- 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.5, fribidi 1.0.8, harfbuzz 14.2.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
import base64, io
from PIL import Image
data = base64.b64decode("SUkrAAAIAAAIAAAAAAAAAAAAAQABAACXl5eXlZeXAJcAawCXAAA=")
Image.open(io.BytesIO(data))   # OverflowError: Python int too large to convert to C ssize_t

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