mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-09-10 06:12:27 +03:00
Improved _accept length check
This commit is contained in:
parent
9f5d1f71a0
commit
009444f9c5
|
@ -30,7 +30,7 @@ from ._util import DeferredError
|
||||||
|
|
||||||
def _accept(prefix: bytes) -> bool:
|
def _accept(prefix: bytes) -> bool:
|
||||||
return (
|
return (
|
||||||
len(prefix) >= 6
|
len(prefix) >= 16
|
||||||
and i16(prefix, 4) in [0xAF11, 0xAF12]
|
and i16(prefix, 4) in [0xAF11, 0xAF12]
|
||||||
and i16(prefix, 14) in [0, 3] # flags
|
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:
|
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):
|
class GribStubImageFile(ImageFile.StubImageFile):
|
||||||
|
|
|
@ -39,7 +39,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix: bytes) -> bool:
|
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:
|
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