Skip to content

Conversation

@ulysses-you
Copy link
Contributor

What changes were proposed in this pull request?

Add overflow check before do new byte[].

Why are the changes needed?

Avoid overflow in extreme case.

Does this PR introduce any user-facing change?

Maybe yes, the error msg changed if overflow.

How was this patch tested?

Pass CI.

@ulysses-you
Copy link
Contributor Author

cc @maropu @MaxGekk

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

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

How about:

@ulysses-you
Copy link
Contributor Author

int size = numBytes - delim.numBytes - idx;
byte[] bytes = new byte[size];

The second place seems will never overflow. Any reason to assert not overflow here ?

@MaxGekk
Copy link
Member

MaxGekk commented Apr 13, 2021

The second place seems will never overflow. Any reason to assert not overflow here ?

ok. It seems we can guarantee that numBytes > idx + delim.numBytes and size <= Int.MaxValue

Comment on lines 766 to 767
int resultSize = Math.toIntExact((long)numBytes * times);
byte[] newBytes = new byte[resultSize];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int resultSize = Math.toIntExact((long)numBytes * times);
byte[] newBytes = new byte[resultSize];
byte[] newBytes = new byte[Math.multiplyExact(numBytes, times)];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the carefully review !

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41853/

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41853/

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Test build #137274 has finished for PR 32142 at commit d43643e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41862/

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41862/

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41865/

@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/41865/

@github-actions github-actions bot added the SQL label Apr 13, 2021
@SparkQA
Copy link

SparkQA commented Apr 13, 2021

Test build #137283 has finished for PR 32142 at commit 6f48d88.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@MaxGekk
Copy link
Member

MaxGekk commented Apr 13, 2021

+1, LGTM. Merging to master.
Thank you, @ulysses-you .

@MaxGekk MaxGekk closed this in e70b0f8 Apr 13, 2021
@ulysses-you
Copy link
Contributor Author

thanks for merging

@ulysses-you ulysses-you deleted the SPARK-35041 branch April 13, 2021 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants