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 slicing size byte overflow #77

Merged
merged 3 commits into from
Dec 29, 2023

Conversation

muktihari
Copy link
Owner

@muktihari muktihari commented Dec 29, 2023

n := b[4]
b = d.bytesArray[:n*3] // 3 byte per field

When n is 123 expected value of n*3 is 369, but since n is a byte with max value is 255, it overflows, the result is 113. This cause unexpected behaviour and even panic when trying to access the slice's index more than the available len, since the size does not match the correct size.

Since the maximum of bytesArray is 766, an uint16 should be sufficient for this task.

@muktihari muktihari self-assigned this Dec 29, 2023
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (88a8072) 100.00% compared to head (e947633) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #77   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           28        28           
  Lines         3090      3098    +8     
=========================================
+ Hits          3090      3098    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@muktihari muktihari added the bug Something isn't working label Dec 29, 2023
@muktihari muktihari merged commit 8b66e5e into master Dec 29, 2023
1 check passed
@muktihari muktihari deleted the fix/decoder-slicing-size-byte-overflow branch December 29, 2023 02:15
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.

2 participants