Skip to content

Commit 19145d7

Browse files
committed
feat: check for size on struct deserialization
1 parent cab64dc commit 19145d7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

libdestruct/common/struct/struct.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
if TYPE_CHECKING:
1414
from libdestruct.common.struct.struct_impl import struct_impl
1515

16+
1617
class struct(obj):
1718
"""A C struct."""
1819

@@ -27,4 +28,9 @@ def from_bytes(cls: type[struct], data: bytes) -> struct_impl:
2728

2829
type_inflater = inflater(data)
2930

30-
return type_inflater.inflate_struct(cls, 0)
31+
result = type_inflater.inflate_struct(cls, 0)
32+
33+
if result.size != len(data):
34+
raise ValueError("The length of the serialized struct does not match the struct size.")
35+
36+
return result

0 commit comments

Comments
 (0)