Skip to content
Open
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
2 changes: 2 additions & 0 deletions fitparse/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def _parse_file_header(self):

# Larger fields are explicitly little endian from SDK
header_size, protocol_ver_enc, profile_ver_enc, data_size = self._read_struct('2BHI4x', data=header_data)
if header_size < 12:
raise FitHeaderError('Irregular File Header Size')

# Decode the same way the SDK does
self.protocol_version = float("%d.%d" % (protocol_ver_enc >> 4, protocol_ver_enc & ((1 << 4) - 1)))
Expand Down
7 changes: 7 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import csv
import datetime
import io
import os
from struct import pack
import warnings
Expand Down Expand Up @@ -74,6 +75,12 @@ def testfile(filename):


class FitFileTestCase(unittest.TestCase):
def test_rejects_header_shorter_than_fit_minimum(self):
header = bytes([11, 16, 0, 0, 0, 0, 0, 0]) + b'.FIT'

with self.assertRaises(FitHeaderError):
FitFile(io.BytesIO(header), check_crc=False)


def test_basic_file_with_one_record(self, endian='<'):
f = FitFile(generate_fitfile(endian=endian))
Expand Down