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

Avoid overflowing int64 in RoundUpSize and return error if overflow int #66464

Merged
merged 1 commit into from Jul 25, 2018

Conversation

wongma7
Copy link
Contributor

@wongma7 wongma7 commented Jul 20, 2018

What this PR does / why we need it:
There are many places in plugins (some I may have missed) that we naively convert a resource.Quantity.Value() which is an int64, to an int, which may be only 32 bits long.

Background, optional to read :): Kubernetes canonicalizes resource.Quantities, and from what I have seen testing creating PVCs, decimalSI is the default. If a quantity is in decimalSI format and its value in bytes would overflow an int64, e.g. 10E, nothing happens. If it is in binarySI and its value in bytes would overflow an int64, e.g. 10Ei, it is set down to 2^63-1 and there's no overflow of the field value. But there may be overflow later in the code which is what this PR is addressing.

  • Change RoundUpSize implementation to avoid overflowing int64
  • Add RoundUp*Int functions for use when an int is expected instead of an int64, because int may be 32bits and naively doing int($INT64_VALUE) can lead to silent overflow. These functions return an error if overflow has occurred.
  • Rename *GB variables to *GiB where appropriate for maximum clarity
  • Use RoundUpToGiB instead of RoundUpSize where possible

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer: please review carefully as we don't have e2e tests for most plugins!

Release note:

NONE

edit: remove 'we do not need to worry about...'. yes we do, i worded that badly :))

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 20, 2018
@wongma7
Copy link
Contributor Author

wongma7 commented Jul 20, 2018

/cc @jsafrane if you are curious
/sig storage
@kubernetes/sig-storage-pr-reviews
related but not sure if my PR fixes it as I may have missed it going through every plugin: #56647

@k8s-ci-robot k8s-ci-robot added sig/storage Categorizes an issue or PR as relevant to SIG Storage. labels Jul 20, 2018
@k8s-ci-robot
Copy link
Contributor

@wongma7: GitHub didn't allow me to request PR reviews from the following users: if, you, are, curious.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @jsafrane if you are curious
/sig storage
@kubernetes/sig-storage-pr-reviews
related but not sure if my PR fixes it as I may have missed it going through every plugin: #56647

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -376,6 +380,32 @@ func RoundUpToGiB(size resource.Quantity) int64 {
return RoundUpSize(requestBytes, GIB)
}

// RoundUpSizeInt calculates how many allocation units are needed to accommodate
// a volume of given size. It returns an int instead of an int64 and true if
Copy link
Contributor Author

Choose a reason for hiding this comment

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

says 'return true', i will fix the comment on monday

@humblec
Copy link
Contributor

humblec commented Jul 21, 2018

@wongma7 Thanks for the fix!! Yeah, this overflow was not handled and its causing issues.

@anguslees
Copy link
Member

lgtm, waiting for the "return true" comment to be updated to make it official.

(I particularly appreciate the attention to detail around GB vs GiB)

@jsafrane
Copy link
Member

@wongma7, thanks for working on this!

@wongma7
Copy link
Contributor Author

wongma7 commented Jul 23, 2018

comments updated, thanks for the quick review @anguslees

Copy link
Member

@anguslees anguslees left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 24, 2018
@anguslees
Copy link
Member

/assign @dnardo @gnufied

@gnufied
Copy link
Member

gnufied commented Jul 24, 2018

/approve

@gnufied
Copy link
Member

gnufied commented Jul 24, 2018

cc @msau42 @jingxu97

@saad-ali
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: anguslees, gnufied, saad-ali, wongma7

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 25, 2018
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 66464, 66488). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 35c3764 into kubernetes:master Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/storage Categorizes an issue or PR as relevant to SIG Storage. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants