Skip to content

Commit

Permalink
Add test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
lajiyuan committed Jan 12, 2024
1 parent b9c37d2 commit 23fd509
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Binary file added Tests/images/end_trunc_file.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 13 additions & 11 deletions Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,18 +786,20 @@ class TestTruncatedPngPLeaks(PillowLeakTestCase):
iterations = 100 # Leak is 56k/iteration, this will leak 5.6megs

def test_leak_load(self):
with open("Tests/images/hopper.png", "rb") as f:
DATA = BytesIO(f.read(16 * 1024))
files = ['Tests/images/hopper.png', 'Tests/images/end_trunc_file.png']
for file in files:
with open(file, "rb") as f:
DATA = BytesIO(f.read(16 * 1024))

ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open(DATA) as im:
im.load()

def core():
ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open(DATA) as im:
im.load()

try:
self._test_leak(core)
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False
def core():
with Image.open(DATA) as im:
im.load()

try:
self._test_leak(core)
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False

0 comments on commit 23fd509

Please sign in to comment.