mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-09-09 22:02:27 +03:00
Improve _accept length check (#9170)
This commit is contained in:
commit
bde90757fa
|
@ -30,7 +30,7 @@ from ._util import DeferredError
|
|||
|
||||
def _accept(prefix: bytes) -> bool:
|
||||
return (
|
||||
len(prefix) >= 6
|
||||
len(prefix) >= 16
|
||||
and i16(prefix, 4) in [0xAF11, 0xAF12]
|
||||
and i16(prefix, 14) in [0, 3] # flags
|
||||
)
|
||||
|
|
|
@ -33,7 +33,7 @@ def register_handler(handler: ImageFile.StubHandler | None) -> None:
|
|||
|
||||
|
||||
def _accept(prefix: bytes) -> bool:
|
||||
return prefix.startswith(b"GRIB") and prefix[7] == 1
|
||||
return len(prefix) >= 8 and prefix.startswith(b"GRIB") and prefix[7] == 1
|
||||
|
||||
|
||||
class GribStubImageFile(ImageFile.StubImageFile):
|
||||
|
|
|
@ -39,7 +39,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def _accept(prefix: bytes) -> bool:
|
||||
return prefix[0] == 10 and prefix[1] in [0, 2, 3, 5]
|
||||
return len(prefix) >= 2 and prefix[0] == 10 and prefix[1] in [0, 2, 3, 5]
|
||||
|
||||
|
||||
##
|
||||
|
|
|
@ -47,7 +47,7 @@ MODES = {
|
|||
|
||||
|
||||
def _accept(prefix: bytes) -> bool:
|
||||
return prefix.startswith(b"P") and prefix[1] in b"0123456fy"
|
||||
return len(prefix) >= 2 and prefix.startswith(b"P") and prefix[1] in b"0123456fy"
|
||||
|
||||
|
||||
##
|
||||
|
|
Loading…
Reference in New Issue
Block a user