Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TGA color map entry size is only 1 byte #5396

Merged
merged 1 commit into from Apr 18, 2021

Conversation

radarhere
Copy link
Member

In the TGA format, color map entry size is 1 byte.

Color map specification (field 4)
has three subfields:

  • First entry index (2 bytes): index of first color map entry that is included in the file
  • Color map length (2 bytes): number of entries of the color map that are included in the file
  • Color map entry size (1 byte): number of bits per pixel

It is currently read as 2 bytes though -

start, size, mapdepth = i16(s, 3), i16(s, 5), i16(s, 7)

This PR updates it to 1 byte rather than 2 - and as per #4614, it is written as s[7] rather than i8(s, 7).

The reason that this hasn't been noticed is because the next byte is the 'X-origin', and I presume this is usually zero. As a test case, I've copied one of the existing test images and hexedited it so this isn't the case.

Credit to https://stackoverflow.com/a/63156250/4093019 for pointing this out, linked to from #4830

@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Apr 16, 2021
@hugovk hugovk merged commit 50fdc15 into python-pillow:master Apr 18, 2021
@radarhere radarhere deleted the mapdepth branch April 18, 2021 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants