Skip to content

Commit

Permalink
Move header length check into cython-code
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Oct 6, 2022
1 parent e1fa532 commit 849bb19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/eventio/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def check_size_or_raise(data, expected_length, zero_ok=True):
else:
raise EOFError('File seems to be truncated')

if length < expected_length:
elif length < expected_length:
raise EOFError('File seems to be truncated')


Expand All @@ -186,12 +186,6 @@ def read_header(byte_stream, offset, toplevel=False):
'''

header_bytes = byte_stream.read(constants.OBJECT_HEADER_SIZE)
check_size_or_raise(
header_bytes,
constants.OBJECT_HEADER_SIZE,
zero_ok=False,
)

header = parse_header_bytes(header_bytes, toplevel=toplevel)

if header.extended:
Expand Down
5 changes: 5 additions & 0 deletions src/eventio/header.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ cpdef ObjectHeader parse_header_bytes(const uint8_t[:] header_bytes, bint toplev
cdef bint only_subobjects
cdef uint64_t length

if len(header_bytes) != OBJECT_HEADER_SIZE:
# for backwards compatibility, we raise the same error as before.
# more appropriate for this free function would be something like
# raise ValueError("header_bytes size must be 12")
raise EOFError('File seems to be truncated')

type_int = unpack_uint32(header_bytes[0:4])
type_, version, user, extended = parse_type_field(type_int)
Expand Down

0 comments on commit 849bb19

Please sign in to comment.