Skip to content

Commit ed6dfbf

Browse files
committed
fix: Opening HEIC images now throws UnidentifiedImageError
This will allow pillow-avif-plugin to be interoperable with the HEIC opener in pillow_heif. Fixes fdintino#19.
1 parent 1dc3cab commit ed6dfbf

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ Changelog
1111
``save()``).
1212
* **Fixed**: ``tile_cols`` encoder setting (the ``save()`` method was using
1313
the value passed to ``tile_rows`` instead)
14+
* **Fixed**: Attempts to open non-AV1 images in HEIF containers (e.g. HEIC)
15+
now raises UnidentifiedImageError, not ValueError. Fixes `#19`_.
1416
* **CI**: manylinux2014 aarch64 wheels
1517
* **CI**: bundle libyuv and libsharpyuv
1618
* **CI**: Python 3.11 wheels
1719
* **CI**: Update bundled libraries (see table below, changes from previous
1820
release in bold)
1921

22+
.. _#19: https://github.com/fdintino/pillow-avif-plugin/issues/19
23+
2024
.. table::
2125

2226
=========== ==========

src/pillow_avif/_avif.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ normalize_tiles_log2(int value) {
125125
static PyObject *
126126
exc_type_for_avif_result(avifResult result) {
127127
switch (result) {
128-
case AVIF_RESULT_INVALID_FTYP:
129128
case AVIF_RESULT_INVALID_EXIF_PAYLOAD:
130129
case AVIF_RESULT_INVALID_CODEC_SPECIFIC_OPTION:
131130
return PyExc_ValueError;
131+
case AVIF_RESULT_INVALID_FTYP:
132132
case AVIF_RESULT_BMFF_PARSE_FAILED:
133133
case AVIF_RESULT_TRUNCATED_DATA:
134134
case AVIF_RESULT_NO_CONTENT:

tests/images/rgba10.heif

7.2 KB
Binary file not shown.

tests/test_file_avif.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,11 @@ def test_sequence_dimension_mismatch_check(self, tmp_path):
648648
with pytest.raises(ValueError):
649649
frame1.save(temp_file, save_all=True, append_images=[frame2], duration=100)
650650

651+
def test_heif_raises_unidentified_image_error(self):
652+
with pytest.raises(UnidentifiedImageError or IOError):
653+
with Image.open("tests/images/rgba10.heif"):
654+
pass
655+
651656
@skip_unless_avif_version_gte((0, 9, 0))
652657
@pytest.mark.parametrize("alpha_premultipled", [False, True])
653658
def test_alpha_premultiplied_true(self, alpha_premultipled):

0 commit comments

Comments
 (0)