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

pgcryptocipherccl: don't panic when passed invalid padding size #110408

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

andyyang890
Copy link
Collaborator

@andyyang890 andyyang890 commented Sep 12, 2023

This patch modifies zeroPadOrTruncate to return an error instead of panicking
when it is passed an invalid (i.e. negative) padding size. Note that this is
currently only possible as the result of programmer error.

We also add a unit test to validate the function's expected behavior.

Informs #21001

Release note: None

@andyyang890 andyyang890 requested a review from a team as a code owner September 12, 2023 05:42
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andyyang890 andyyang890 force-pushed the test_zero_pad branch 2 times, most recently from 00619f1 to a8cbd7d Compare September 12, 2023 06:23
@andyyang890 andyyang890 changed the title pgcryptocipherccl: add a unit test for zeroPadOrTruncate pgcryptocipherccl: don't panic when passed invalid padding size Sep 12, 2023
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andyyang890 and @ecwall)


pkg/ccl/pgcryptoccl/pgcryptocipherccl/padding.go line 59 at r1 (raw file):

func zeroPadOrTruncate(data []byte, size int) ([]byte, error) {
	if size < 0 {
		return nil, errors.New("cannot zero pad or truncate to negative size")

super nit: consider errors.AssertionFailed here

This patch modifies `zeroPadOrTruncate` to return an error instead of panicking
when it is passed an invalid (i.e. negative) padding size. Note that this is
currently only possible as the result of programmer error.

We also add a unit test to validate the function's expected behavior.

Release note: None
Copy link
Collaborator Author

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @rafiss)


pkg/ccl/pgcryptoccl/pgcryptocipherccl/padding.go line 59 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

super nit: consider errors.AssertionFailed here

good catch, changed!

@andyyang890
Copy link
Collaborator Author

tftr!

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Sep 15, 2023

Build succeeded:

@craig craig bot merged commit 28552c8 into cockroachdb:master Sep 15, 2023
@andyyang890 andyyang890 deleted the test_zero_pad branch September 15, 2023 13:15
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