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

Conversation

dhurley
Copy link
Collaborator

@dhurley dhurley commented May 9, 2024

Proposed changes

Add additional checks in chunking functionality

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • I have run make install-tools and have attached any dependency changes to this pull request
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes
  • If applicable, I have updated any relevant documentation (README.md)
  • If applicable, I have tested my cross-platform changes on Ubuntu 22, Redhat 8, SUSE 15 and FreeBSD 13

@github-actions github-actions bot added chore Pull requests for routine tasks dependencies labels May 9, 2024
Copy link

netlify bot commented May 9, 2024

Deploy Preview for agent-public-docs canceled.

Name Link
🔨 Latest commit 5275787
🔍 Latest deploy log https://app.netlify.com/sites/agent-public-docs/deploys/663cd3d5647b7300086907fb

sdk/checksum/checksum.go Fixed Show fixed Hide fixed
@dhurley dhurley self-assigned this May 9, 2024
@dhurley dhurley marked this pull request as ready for review May 9, 2024 10:37
return [][]byte{buf}
}

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.

Comment on lines 43 to 52
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{}
}
Copy link
Contributor

@Dean-Coakley Dean-Coakley May 9, 2024

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

sdk/checksum/checksum.go Fixed Show fixed Hide fixed
@dhurley dhurley merged commit a498a43 into main May 9, 2024
33 checks passed
@dhurley dhurley deleted the update-checksum-chuck-function branch May 9, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Pull requests for routine tasks dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants