@@ -777,6 +777,16 @@ class MyStdOut:
777777 mystdout = mystdout .buffer
778778 with Image .open (mystdout ) as reloaded :
779779 assert_image_equal_tofile (reloaded , TEST_PNG_FILE )
780+
781+ def test_end_truncated_filed (self ):
782+ ImageFile .LOAD_TRUNCATED_IMAGES = True
783+ try :
784+ img = Image .open ("Tests/images/end_trunc_file.png" )
785+ img .load ()
786+ assert img is not None
787+ finally :
788+ ImageFile .LOAD_TRUNCATED_IMAGES = False
789+
780790
781791
782792@pytest .mark .skipif (is_win32 (), reason = "Requires Unix or macOS" )
@@ -786,20 +796,18 @@ class TestTruncatedPngPLeaks(PillowLeakTestCase):
786796 iterations = 100 # Leak is 56k/iteration, this will leak 5.6megs
787797
788798 def test_leak_load (self ):
789- files = ['Tests/images/hopper.png' , 'Tests/images/end_trunc_file.png' ]
790- for file in files :
791- with open (file , "rb" ) as f :
792- DATA = BytesIO (f .read (16 * 1024 ))
799+ with open ("Tests/images/hopper.png" , "rb" ) as f :
800+ DATA = BytesIO (f .read (16 * 1024 ))
793801
794- ImageFile .LOAD_TRUNCATED_IMAGES = True
802+ ImageFile .LOAD_TRUNCATED_IMAGES = True
803+ with Image .open (DATA ) as im :
804+ im .load ()
805+
806+ def core ():
795807 with Image .open (DATA ) as im :
796808 im .load ()
797809
798- def core ():
799- with Image .open (DATA ) as im :
800- im .load ()
801-
802- try :
803- self ._test_leak (core )
804- finally :
805- ImageFile .LOAD_TRUNCATED_IMAGES = False
810+ try :
811+ self ._test_leak (core )
812+ finally :
813+ ImageFile .LOAD_TRUNCATED_IMAGES = False
0 commit comments