File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,19 @@ def test_truncated_file(tmp_path):
145145 im .load ()
146146
147147
148+ @pytest .mark .parametrize ("maxval" , (0 , 65536 ))
149+ def test_invalid_maxval (maxval , tmp_path ):
150+ path = str (tmp_path / "temp.ppm" )
151+ with open (path , "w" ) as f :
152+ f .write ("P6\n 3 1 " + str (maxval ))
153+
154+ with pytest .raises (ValueError ) as e :
155+ with Image .open (path ):
156+ pass
157+
158+ assert str (e .value ) == "maxval must be greater than 0 and less than 65536"
159+
160+
148161def test_neg_ppm ():
149162 # Storage.c accepted negative values for xsize, ysize. the
150163 # internal open_ppm function didn't check for sanity but it
Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ def _open(self):
116116 break
117117 elif ix == 2 : # token is maxval
118118 maxval = token
119+ if not 0 < maxval < 65536 :
120+ raise ValueError (
121+ "maxval must be greater than 0 and less than 65536"
122+ )
119123 if maxval > 255 and mode == "L" :
120124 self .mode = "I"
121125
You can’t perform that action at this time.
0 commit comments