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 multiplication overflow in ValidateEncodingParams #1341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ian-shim
Copy link
Contributor

@ian-shim ian-shim commented Feb 28, 2025

Why are these changes needed?

Ensure that params.ChunkLength*params.NumChunks doesn't result in overflow

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@ian-shim ian-shim requested review from anupsv and jianoaix February 28, 2025 00:42
@ian-shim ian-shim marked this pull request as ready for review February 28, 2025 00:43
@@ -11,6 +11,8 @@ var (
ErrInvalidParams = errors.New("invalid encoding params")
)

const maxUint64 = ^uint64(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

just use existing constant math.MaxUint64 should be sufficient

@@ -61,6 +63,9 @@ func GetNumSys(dataSize uint64, chunkLen uint64) uint64 {

// ValidateEncodingParams takes in the encoding parameters and returns an error if they are invalid.
func ValidateEncodingParams(params EncodingParams, SRSOrder uint64) error {
if params.ChunkLength != 0 && params.NumChunks > maxUint64/params.ChunkLength {
Copy link
Contributor

Choose a reason for hiding this comment

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

should it check if ChunkLength / NumChunks are 0 as well?

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