Skip to content

Some TIFF files are identified as FLI/FLC files #9168

Description

@vpv-csc

We operate and develop a digital preservation system. One of our users has TIFF files, which Pillow's FliImagePlugin identifies as FLI/FLC files. I can not share these files, but I can give you some details of them.

What did you do?

Here is a simple test code

import PIL.Image

image = PIL.Image.open("testfile.tiff")
print(image.format)
print(image.get_format_mimetype())

What did you expect to happen?

The output should be

TIFF
image/tiff

What actually happened?

The output is

FLI
None

What are your OS, Python and Pillow versions?

  • OS: Fedora 42 (a container)
  • Python: Python 3.13.7
  • Pillow: main branch compiled/installed from soure
--------------------------------------------------------------------
Pillow 12.0.0.dev0
Python 3.13.7 (main, Aug 14 2025, 00:00:00) [GCC 15.2.1 20250808 (Red Hat 15.2.1-1)]
--------------------------------------------------------------------
Python executable is /home/vvainio/scratch/Pillow/venv/bin/python
Environment Python files loaded from /home/vvainio/scratch/Pillow/venv
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/vvainio/scratch/Pillow/venv/lib64/python3.13/site-packages/PIL
Binary Pillow modules loaded from /home/vvainio/scratch/Pillow/venv/lib64/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.0.0.dev0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.5.0
*** AVIF support not installed
--- JPEG support ok, compiled for libjpeg-turbo 3.1.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.2.5
--- LIBTIFF support ok, loaded 4.7.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok
--------------------------------------------------------------------

Additional information

In hex code, our example image starts like this:
4949 2a00 12af cb02

Probably due to software used to produce these files, the TIFF IFD location has 0x12 as byte 4 and 0xAF as byte 5 in the file. This is enough to have FliImagePlugin consider it an FLI file. Byte 14 is 0 (and so are bytes 20-22, even though those are checked outside of _accept()). Bytes 14 and 20-22 are already image data of strip 1, so they are outside the TIFF header.

The FLI and FLC detection syntax in file/libmagic (here https://github.com/file/file/blob/master/magic/Magdir/animation#L878) checks that byte 12 is always 8, as in 8-bit colour depth. That check would be enough to differentiate these TIFFs from FLIs/FLCs.

The page https://www.compuphase.com/flic.htm says about this about the type field in the FLI/FLC file header:
"0xAF11 For FLI files
0xAF12 For standard FLC files (with an 8-bit colour depth)."

Checking for 8-bit colour depth would work here, because Pillow does not seem to support types 0xAF44, 0xAF30 or 0xAF31 at all. I'll add a PR about that.

Checking for the reserved areas of the FLI/FLC file would make the detection even better. You already check for bytes 20-22 in _open(). The other reserved areas are in offsets 48-72 and 80-120. These checks can not be made in _accept(), because the _accept() prefix is only 16 bytes long, so they would not solve this issue.

One option would be to increase the priority of detecting TIFF files. I'm quite certain there are more TIFF files than FLI/FLC files around. Could you consider adding TIFF as a format to preinit() in Image.py? Or is there some other way to control the priority?

Activity

  1. radarhere commented on Aug 21, 2025

    @radarhere
    Member

    Or is there some other way to control the priority?

    I'm not sure if you're asking from a user perspective or not, but Image.open() has a formats argument that allows you to specify which formats you would like to accept.

    Or you could adjust the list of registered extensions in Image.OPEN. Here's an example that removes FLI.

    >>> from PIL import Image
    >>> Image.init()
    True
    >>> del Image.OPEN["FLI"]
  2. radarhere commented on Aug 30, 2025

    @radarhere
    Member

    I don't suppose you could attach the image file?

  3. vpv-csc commented on Sep 1, 2025

    @vpv-csc
    Author

    Unfortunately I can't.

  4. jukuisma commented on Sep 2, 2025

    @jukuisma

    I was able to reproduce this earlier by editing our existing test files based on the description. That we can attach here. Give me a sec.

  5. jukuisma commented on Sep 2, 2025

    @jukuisma

    Had another look and discussed with @vpv-csc. Unfortunately generating valid test images from scratch isn't as trivial as I thought. Sorry for the false hope..

  6. radarhere commented on Sep 3, 2025

    @radarhere
    Member

    Checking for the reserved areas of the FLI/FLC file would make the detection even better. You already check for bytes 20-22 in _open(). The other reserved areas are in offsets 48-72 and 80-120. These checks can not be made in _accept(), because the _accept() prefix is only 16 bytes long, so they would not solve this issue.

    I've created #9183 for this.

  7. vpv-csc commented on Sep 4, 2025

    @vpv-csc
    Author

    #9183 fixes this issue even without my PR #9169. I'll leave it up to the maintainers to decide whether to apply only #9183 or both.

  8. changed the title [-]Some TIFF files are identified FLI/FLC files[/-] [+]Some TIFF files are identified as FLI/FLC files[/+] on Sep 6, 2025
  9. vpv-csc commented on Oct 2, 2025

    @vpv-csc
    Author

    If you are nearing next release, could you consider merging at least #9183?

  10. radarhere commented on Oct 2, 2025

    @radarhere
    Member

    I understand it looks like it might not make it in, but there does tend to be a flurry of reviews a week or so before release. It's just waiting on another core team member to review. I've added it to the 12.0.0 milestone so we won't forget it.

  11. hugovk commented on Oct 4, 2025

    @hugovk
    Member

    Merged, thank you for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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