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

Check overflow for memory read #121

Closed
wants to merge 1 commit into from
Closed

Conversation

mininny
Copy link
Collaborator

@mininny mininny commented Jan 13, 2025

Description

Check for memory read overflow in rvgo/fast implementation.
We can check if r.addr + r.count exceeds uint64.max value so that memory read overflow results in error.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 61.80%. Comparing base (bf4e465) to head (9826ad5).

Files with missing lines Patch % Lines
rvgo/fast/memory.go 0.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #121      +/-   ##
==========================================
- Coverage   61.87%   61.80%   -0.08%     
==========================================
  Files          27       27              
  Lines        4126     4131       +5     
==========================================
  Hits         2553     2553              
- Misses       1432     1436       +4     
- Partials      141      142       +1     

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

@@ -283,6 +283,12 @@ func (r *memReader) Read(dest []byte) (n int, err error) {
return 0, io.EOF
}

if r.addr > 1<<64-1-r.count {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can r.count exceed 63 causing underflow? Maybe it makes sense to do the following?

Suggested change
if r.addr > 1<<64-1-r.count {
if r.count < 64 && r.addr > 1<<64-1-r.count {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done to check if the r.addr + r.count does not exceed uint64 max (1<<64-1). I think bit shift has higher operator precedence than subtraction, so underflow won't happen.

@mininny
Copy link
Collaborator Author

mininny commented Jan 17, 2025

Because address space is circular and wrap around in asterisc, we shouldn't assert the maximum address range. See finding#2.

@mininny mininny closed this Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants