Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decoder now handle bad encoded fit file when size < basetype.Size #177

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

muktihari
Copy link
Owner

@muktihari muktihari commented Apr 10, 2024

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.

@muktihari muktihari added the bug Something isn't working label Apr 10, 2024
@muktihari muktihari self-assigned this Apr 10, 2024
@muktihari muktihari merged commit cc98153 into master Apr 10, 2024
4 checks passed
@muktihari muktihari deleted the fix/decoder-handle-bad-encoded-fit-file branch April 10, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant