polyvertex / fitdecode

A FIT file parsing and decoding library written in Python3
MIT License
157 stars 34 forks source link

FIT Parse Error exception #17

Closed dakiphart closed 3 years ago

dakiphart commented 3 years ago

When I parse the attached file I get a FITParseError exception. The problem is the file contains a record chunk which consists of a single tab character. The FIT file was downloaded from RideWithGPS. I am using Python3.7 and fitdecode v0.7.0.

The same error occurs if I use the fittxt utility included in fitdecode.

The FIT file is most likely invalid but it would be nice if there was a way to ignore the bad record chunk and continue parsing the file, if that is possible.

Here is the stack traceback.

Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/fitdecode/reader.py", line 536, in _read_data_message def_mesg = self._local_mesg_defs[record_header.local_mesg_num] KeyError: 9

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./fitdump.py", line 83, in dumper.run() File "./fitdump.py", line 76, in run for frame in fit: File "/usr/local/lib/python3.7/site-packages/fitdecode/reader.py", line 188, in iter yield from self._read_next() File "/usr/local/lib/python3.7/site-packages/fitdecode/reader.py", line 295, in _read_next record = self._read_record() File "/usr/local/lib/python3.7/site-packages/fitdecode/reader.py", line 434, in _read_record message = self._read_data_message(chunk, record_header) File "/usr/local/lib/python3.7/site-packages/fitdecode/reader.py", line 540, in _read_data_message f'local message {record_header.local_mesg_num} not defined') fitdecode.exceptions.FitParseError: FIT parsing error @ 142600: local message 9 not defined

bad-fit.zip

polyvertex commented 3 years ago

Hey, thanks for providing this.

This requires more digging but at first glance it looks like your file is truncated. Parsing error pops at offset 142600, so 2 bytes only before the end of file. Also, last valid message is a stop_disable_all event.

I will check if I can make the parser more permissive on truncated files.

polyvertex commented 3 years ago

Well, it appears in this particular case I cannot make fitdecode more permissive because this error occurs before parser even tries to read the 2 following bytes.

Bottom line is, only solution is to just strip the 2 last bytes off this file.

dakiphart commented 3 years ago

No worries.  I modified my code to save whatever data I get. The truncation may be the fault of Ride With GPS or possibly my browser or MacOS.Thanks for looking into this problem.