Skip to content

Commit

Permalink
fix FLI/FLC decoder for files with a prefix chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
twolife committed Feb 17, 2024
1 parent 47eaf09 commit 4934da5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Binary file added Tests/images/2422.flc
Binary file not shown.
20 changes: 18 additions & 2 deletions Tests/test_file_fli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

import pytest

from PIL import FliImagePlugin, Image
from PIL import FliImagePlugin, Image, ImageFile

from .helper import assert_image_equal, assert_image_equal_tofile, is_pypy

# created as an export of a palette image from Gimp2.6
# save as...-> hopper.fli, default options.
static_test_file = "Tests/images/hopper.fli"

# From https://samples.libav.org/fli-flc/
# From https://samples.ffmpeg.org/fli-flc/
animated_test_file = "Tests/images/a.fli"

# From https://samples.ffmpeg.org/fli-flc/
animated_flc_with_prefixchunk_test_file = "Tests/images/2422.flc"


def test_sanity() -> None:
with Image.open(static_test_file) as im:
Expand All @@ -31,6 +34,19 @@ def test_sanity() -> None:
assert im.info["duration"] == 71
assert im.is_animated

ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open(animated_flc_with_prefixchunk_test_file) as im:
assert im.mode == "P"
assert im.size == (320, 200)
assert im.format == "FLI"
assert im.info["duration"] == 171
assert im.is_animated
palette = im.getpalette()
assert (palette[3], palette[4], palette[5]) == (255, 255, 255)
assert (palette[381], palette[382], palette[383]) == (204, 204, 12)
assert (palette[765], palette[766], palette[767]) == (252, 0, 0)
ImageFile.LOAD_TRUNCATED_IMAGES = False


@pytest.mark.skipif(is_pypy(), reason="Requires CPython")
def test_unclosed_file() -> None:
Expand Down
1 change: 1 addition & 0 deletions src/PIL/FliImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _open(self):
if i16(s, 4) == 0xF100:
# prefix chunk; ignore it
self.__offset = self.__offset + i32(s)
self.fp.seek(self.__offset)

Check warning on line 80 in src/PIL/FliImagePlugin.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/FliImagePlugin.py#L80

Added line #L80 was not covered by tests
s = self.fp.read(16)

if i16(s, 4) == 0xF1FA:
Expand Down

0 comments on commit 4934da5

Please sign in to comment.