8000 MPO encoding then decoding does not work · Issue #8977 · python-pillow/Pillow · GitHub
[go: up one dir, main page]

Skip to content
MPO encoding then decoding does not work #8977
@misaka-10032

Description

@misaka-10032

What did you do?

I encoded a list of image into MPO and decoded them. Decoding failed to return multiple images.

What did you expect to happen?

The MPO plugin should be able to decode the MPO encoded by its own.

What actually happened?

Decoder complains that the file is truncated.

What are your OS, Python and Pillow versions?

  • OS: Linux
  • Python: 3.10.12
  • Pillow: 11.2.1 (I also tried 9.5.0, 10.4.0. Same error)
import io
import PIL.Image

frames = [PIL.Image.new("RGB", (512, 512), c) for c in ["red", "green", "blue"]]
with io.BytesIO() as f:
  frames[0].save(
      f, format="MPO", save_all=True, append_images=frames[1:]
  )
  mpo_bytes = f.getvalue()
with io.BytesIO(mpo_bytes) as f:
  mpo_image = PIL.Image.open(f)
  print(mpo_image.n_frames)

Logs:

> /usr/local/lib/python3.10/dist-packages/PIL/TiffImagePlugin.py:950: UserWarning: Truncated File Read
>  warnings.warn(str(msg))
> /usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py:890: UserWarning: Image appears to be a malformed MPO file, it will be interpreted as a base JPEG file
>  warnings.warn(
>
> [/usr/local/lib/python3.10/dist-packages/PIL/JpegImagePlugin.py](https://localhost:8080/#) in __getattr__(self, name)
>    398             deprecate(name, 12)
>    399             return getattr(self, "_" + name)
> --> 400         raise AttributeError(name)
>    401 
>    402     def __getstate__(self) -> list[Any]:
>
> AttributeError: n_frames

The same works for GIF, but fails for MPO.

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

      0