Skip to content

Commit bde9075

Browse files
authored
Improve _accept length check (#9170)
2 parents f9db7a3 + 009444f commit bde9075

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/PIL/FliImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def _accept(prefix: bytes) -> bool:
3232
return (
33-
len(prefix) >= 6
33+
len(prefix) >= 16
3434
and i16(prefix, 4) in [0xAF11, 0xAF12]
3535
and i16(prefix, 14) in [0, 3] # flags
3636
)

src/PIL/GribStubImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def register_handler(handler: ImageFile.StubHandler | None) -> None:
3333

3434

3535
def _accept(prefix: bytes) -> bool:
36-
return prefix.startswith(b"GRIB") and prefix[7] == 1
36+
return len(prefix) >= 8 and prefix.startswith(b"GRIB") and prefix[7] == 1
3737

3838

3939
class GribStubImageFile(ImageFile.StubImageFile):

src/PIL/PcxImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040

4141
def _accept(prefix: bytes) -> bool:
42-
return prefix[0] == 10 and prefix[1] in [0, 2, 3, 5]
42+
return len(prefix) >= 2 and prefix[0] == 10 and prefix[1] in [0, 2, 3, 5]
4343

4444

4545
##

src/PIL/PpmImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848

4949
def _accept(prefix: bytes) -> bool:
50-
return prefix.startswith(b"P") and prefix[1] in b"0123456fy"
50+
return len(prefix) >= 2 and prefix.startswith(b"P") and prefix[1] in b"0123456fy"
5151

5252

5353
##

0 commit comments

Comments
 (0)