Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/activity_parser/parse_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def decode_fit(
except (gzip.BadGzipFile, zlib.error, EOFError) as e:
raise FitError(str(e)) from e

if not data:
raise FitError("Empty FIT file")

messages, errors = Decoder(Stream.from_byte_array(data)).read(
enable_crc_check=check_crc, merge_heart_rates=merge_heart_rates
)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_parse_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@ def test_non_fit_bytes_raise():
parse_fit(io.BytesIO(b"this is not a FIT file"))


@pytest.mark.parametrize("parser", [parse_fit, parse_fit_raw])
def test_zero_byte_file_raises(parser):
with pytest.raises(FitError, match="[Ee]mpty"):
parser(io.BytesIO(b""))


@pytest.mark.parametrize("parser", [parse_fit, parse_fit_raw])
def test_short_garbage_stub_raises(parser):
with pytest.raises(FitError, match="not a fit file"):
parser(io.BytesIO(b"\x00" * 13))


@pytest.mark.parametrize(
"corrupt_bytes",
[
Expand Down