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

Fix s3 adapter access content length without nil check #5499

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

nopcoder
Copy link
Contributor

Fix #5498

@nopcoder nopcoder added bug Something isn't working area/block-adapter include-changelog PR description should be included in next release changelog labels Mar 15, 2023
@nopcoder nopcoder requested a review from a team March 15, 2023 21:21
@nopcoder nopcoder self-assigned this Mar 15, 2023
Copy link
Contributor

@arielshaqed arielshaqed left a comment

Choose a reason for hiding this comment

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

I say we delete these lines entirely! But approving for velocity: the change itself is safe.

@@ -308,7 +308,7 @@ func (a *Adapter) Get(ctx context.Context, obj block.ObjectPointer, _ int64) (io
log.WithError(err).Errorf("failed to get S3 object bucket %s key %s", qualifiedKey.StorageNamespace, qualifiedKey.Key)
return nil, err
}
sizeBytes = *objectOutput.ContentLength
sizeBytes = aws.Int64Value(objectOutput.ContentLength)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good, but TBH I don't understand what this line does: it copies the value into a variable, which it then ignores. sizeBytes is not a pointer, I don't see what effect this assignment can have.

Suggested change
sizeBytes = aws.Int64Value(objectOutput.ContentLength)

(I'm actually shocked that Go doesn't flag an unused variable here. It's the sort of thing gcc has been doing for ages now, at least when optimizing.)

Same applies below, too. It looks like a bad leftover.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The variable is referenced in the defer function - so it is just for report the file size as part of the metric.

@nopcoder nopcoder merged commit e0e04d3 into master Mar 16, 2023
@nopcoder nopcoder deleted the fix/s3-get-size branch March 16, 2023 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/block-adapter bug Something isn't working include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 block adater access content-length without nil check
2 participants