forked from kenzuya/unshackle
fix(drm): raise ValueError when a file ends inside a box largesize in read_top_boxes
This commit is contained in:
@@ -273,7 +273,8 @@ def senc_protects_samples(buf: bytes, body: int, end: int) -> bool:
|
||||
def read_top_boxes(f: BinaryIO) -> Iterator[tuple[bytes, bytes | None]]:
|
||||
"""Yield each top-level box type, with the body of a moov or moof. Every other body is skipped.
|
||||
|
||||
Raises ValueError when a moov or moof claims more bytes than the file has left.
|
||||
Raises ValueError when a moov or moof claims more bytes than the file has left, or when the file
|
||||
ends inside the largesize field of a box.
|
||||
"""
|
||||
file_size = os.fstat(f.fileno()).st_size
|
||||
while True:
|
||||
@@ -283,7 +284,10 @@ def read_top_boxes(f: BinaryIO) -> Iterator[tuple[bytes, bytes | None]]:
|
||||
size, kind = struct.unpack(">I4s", head)
|
||||
body_size = size - 8
|
||||
if size == 1:
|
||||
body_size = struct.unpack(">Q", f.read(8))[0] - 16
|
||||
large = f.read(8)
|
||||
if len(large) < 8:
|
||||
raise ValueError(f"{kind!r} box is larger than the rest of the file")
|
||||
body_size = struct.unpack(">Q", large)[0] - 16
|
||||
elif size == 0:
|
||||
return
|
||||
if body_size < 0:
|
||||
|
||||
Reference in New Issue
Block a user