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

Add additional checks in chunking functionality #671

Merged
merged 4 commits into from
May 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up
dhurley committed May 9, 2024
commit 902e5f86375c1857b594d4c278562fb7ad263f5c
12 changes: 1 addition & 11 deletions sdk/checksum/checksum.go
Original file line number Diff line number Diff line change
@@ -10,9 +10,6 @@ package checksum
import (
"crypto/sha256"
"fmt"
"math"

log "github.com/sirupsen/logrus"
)

// Checksum - calculate checksum from []byte
@@ -39,14 +36,7 @@ func Chunk(buf []byte, lim int) [][]byte {
return [][]byte{buf}
}

chuckSize := bufSize / lim

if chuckSize > math.MaxInt64-1 {
log.Error("Unable to chuck payload. Data too large.")
return [][]byte{}
}

chunks := make([][]byte, 0, chuckSize+1)
chunks := make([][]byte, 0)
Copy link
Contributor

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?

Copy link
Contributor

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.


for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.