fix: decoder now handle bad encoded fit file when size < basetype.Size #177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a case where a FIT file generated from a well-known brand contains fieldDef's Size which less than fieldDef's Basetype.Size(): Size is 1 byte but the type is uint32 which should have been 4 bytes. This cause panic in our current implementation since the binary unmarshaler will try to unmarshal 4 bytes but we got only 1 byte in []byte slice, index out of bound.
Actually, we do not want to support bad encoded FIT file as there might be too many cases to handle and adding complexity to our code. However, this bug causes panic in our FIT SDK so we need to take a measurement and gracefully handle such cases.
Returning an error is one of the options, but then we can't get the FIT file contents at all, so let's make a simple workaround to handle that so we could retrieve the contents as much as we can and just write a log message when the Decoder found such cases so user known that the data they are receiving might be changed due to the value type casting.