-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add additional checks in chunking functionality #671
Conversation
✅ Deploy Preview for agent-public-docs canceled.
|
return [][]byte{buf} | ||
} | ||
|
||
chunks := make([][]byte, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we no longer set the capacity for chunks
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Donal answered here at the office, so the reason was that the tool was complaining about our capacity potentially overflowing.
FWIW, I did the math on this one. The capacity was len(buf)/lim+1
meaning the only way we exceed the maximum length of an integer (i.e. overflow) is if the buffer (=buf
) had 2^63 elements in it (so 9,223,372,036,854,775,807 elements) on a 64-bit system. Since buf
is a byte slice, that means you would have 2^63 bytes, which translates to ~9,223 petabytes, meaning you definitely would have run into problem far earlier than when entering this.
sdk/checksum/checksum.go
Outdated
log.Error("Unable to chuck payload, chunk size is too small") | ||
return [][]byte{} | ||
} | ||
|
||
chuckSize := bufSize / lim | ||
|
||
if chuckSize > math.MaxInt64-1 { | ||
log.Error("Unable to chuck payload, data too large") | ||
return [][]byte{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/opt:
chuck
-> chunk
chuckSize
-> chunkSize
Proposed changes
Add additional checks in chunking functionality
Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)