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

P mode TGA writing broke in 9.1.0 #6494

Closed
CTimmerman opened this issue Aug 12, 2022 · 1 comment · Fixed by #6500
Closed

P mode TGA writing broke in 9.1.0 #6494

CTimmerman opened this issue Aug 12, 2022 · 1 comment · Fixed by #6500
Labels

Comments

@CTimmerman
Copy link
Contributor

CTimmerman commented Aug 12, 2022

What did you do?

In https://github.com/CTimmerman/steganography/blob/main/requirements.txt i changed Pillow>=7.2.0,<9.1.0 to Pillow>=7.2.0,<=9.1.0 and ran pip install --upgrade -r requirements.txt && python test\test_steganography.py

What did you expect to happen?

INFO:root:Testing P TGA...
INFO:root:Cover has 1,992 bits / 249 bytes available. (8-bit header)
INFO:root:Message has 176 bits / 22 bytes: b')[i\xf3\x99\xc1XE'... [41, 91, 105, 243, 153, 193, 88, 69]
INFO:root:Data hidden.
INFO:root:Message okay in P TGA.

What actually happened?

INFO:root:Testing P TGA...
INFO:root:Cover has 1,992 bits / 249 bytes available. (8-bit header)
INFO:root:Message has 272 bits / 34 bytes: b'\x08\xf9\xcd\xf4\xfe\x1f\xd0\x94'... [8, 249, 205, 244, 254, 31, 208, 148]
INFO:root:Data hidden.
ERROR:root:image file is truncated (61 bytes not processed)
Traceback (most recent call last):
  File "test\test_steganography.py", line 99, in <module>
    test_fuzz()
  File "test\test_steganography.py", line 61, in test_fuzz
    assert reveal(img) == random_bytes  # nosec
  File "test\../src\steganography.py", line 163, in reveal
    bits = list(get_lowest_bits(cover))
  File "test\../src\steganography.py", line 34, in get_lowest_bits
    for pixel in img.getdata():
  File "C:\Users\C\Documents\code\GitHub\steganography\.venv\lib\site-packages\PIL\Image.py", line 1356, in getdata
    self.load()
  File "C:\Users\C\Documents\code\GitHub\steganography\.venv\lib\site-packages\PIL\ImageFile.py", line 251, in load
    raise OSError(
OSError: image file is truncated (61 bytes not processed)

What are your OS, Python and Pillow versions?

  • OS: Microsoft Windows [Version 10.0.19044.1889]
  • Python: 3.8.5
  • Pillow: 9.1.0

IrfanView 4.54 calls the file generated by Pillow 9.1.0 invalid, whereas output from the same code with Pillow 9.0.1 is no problem. Same with Pillow itself loading it.

from PIL import Image

img = Image.new('P', (100, 20), color="white")
name = 'debug_pillow_9.1.0.tga'
img.save(name)
# Everything seems okay so far, until one tries to use the saved image that was created with the color parameter!
after = Image.open(name).load()
r'''
Using Pillow>=9.1.0:

Traceback (most recent call last):
  File "test\test_Pillow_9.1.0.py", line 59, in <module>
    after = Image.open(name).load()
  File "C:\Users\C\Documents\code\GitHub\steganography\.venv\lib\site-packages\PIL\ImageFile.py", line 195, in load
    self.im = Image.core.map_buffer(
ValueError: buffer is not large enough
'''
@radarhere radarhere changed the title P mode TGA writing broke in 9.1.0. P mode TGA writing broke in 9.1.0 Aug 13, 2022
@radarhere
Copy link
Member

I've created PR #6500 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants