This commit is contained in:
Andrew Murray 2026-05-16 18:28:09 +10:00 committed by GitHub
commit b06e291429
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -124,6 +124,14 @@ class TestFilePng:
with Image.open(test_file):
pass
def test_ihdr_unknown_mode(self) -> None:
fp = BytesIO(chunk(b"IHDR", b"\x00" * 13))
with PngImagePlugin.PngStream(fp) as png:
cid, pos, length = png.read()
png.call(cid, pos, length)
assert png.im_mode == ""
def test_bad_text(self) -> None:
# Make sure PIL can read malformed tEXt chunks (@PIL152)

View File

@ -400,6 +400,9 @@ class PngStream(ChunkStream):
self.text_memory = 0
def __enter__(self) -> PngStream:
return self
def check_text_memory(self, chunklen: int) -> None:
self.text_memory += chunklen
if self.text_memory > MAX_TEXT_MEMORY:
@ -461,7 +464,7 @@ class PngStream(ChunkStream):
self.im_size = i32(s, 0), i32(s, 4)
try:
self.im_mode, self.im_rawmode = _MODES[(s[8], s[9])]
except Exception:
except KeyError:
pass
if s[12]:
self.im_info["interlace"] = 1