Skip to content

Commit 5e83449

Browse files
committed
raise an exception if the header is malformed
1 parent 3d0db58 commit 5e83449

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

jitlog/parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ def _parse_jitlog(fileobj):
5050
If a ParseException is directly raised, this is an error that cannot
5151
be recovered from!
5252
"""
53-
is_jit_log = fileobj.read(1) == const.MARK_JITLOG_HEADER
54-
version = ord(fileobj.read(1)) | (ord(fileobj.read(1)) << 8)
55-
is_32bit = ord(fileobj.read(1))
56-
machine = read_string(fileobj, True)
57-
forest = TraceForest(version, is_32bit, machine)
58-
ctx = ParseContext(forest)
53+
try:
54+
is_jit_log = fileobj.read(1) == const.MARK_JITLOG_HEADER
55+
version = ord(fileobj.read(1)) | (ord(fileobj.read(1)) << 8)
56+
is_32bit = ord(fileobj.read(1))
57+
machine = read_string(fileobj, True)
58+
forest = TraceForest(version, is_32bit, machine)
59+
ctx = ParseContext(forest)
60+
except Exception:
61+
raise ParseException("Header malformed")
62+
#
5963
if not is_jit_log:
6064
raise ParseException("Missing header. Provided input might not be a jitlog!")
6165
if version < JITLOG_MIN_VERSION:

0 commit comments

Comments
 (0)