Skip to content

Commit

Permalink
avoid crash on corrupt footer (#99)
Browse files Browse the repository at this point in the history
* avoid crash on corrupt footer

* catch ParseError only

* change error log to use f-string
  • Loading branch information
mcvain authored Feb 12, 2024
1 parent c48301d commit 5e5398b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import struct
import itertools
import gzip
from xml.etree.ElementTree import fromstring
from xml.etree.ElementTree import fromstring, ParseError
from collections import OrderedDict, defaultdict
import logging
from pathlib import Path
Expand Down Expand Up @@ -328,7 +328,13 @@ def load_xdf(
elif tag == 6:
# read [StreamFooter] chunk
xml_string = f.read(chunklen - 6)
streams[StreamId]["footer"] = _xml2dict(fromstring(xml_string))
try:
streams[StreamId]["footer"] = _xml2dict(fromstring(xml_string))
except ParseError as e:
logger.error(
f"found likely XDF file corruption ({e}), "
"ignoring corrupted XML element in footer."
)
elif tag == 4:
# read [ClockOffset] chunk
temp[StreamId].clock_times.append(
Expand Down

0 comments on commit 5e5398b

Please sign in to comment.