Skip to content

HDDS-15740. Validate partNumber on GetObject and return InvalidPart for out-of-range parts#10670

Open
rich7420 wants to merge 1 commit into
apache:masterfrom
rich7420:HDDS-partnumber-validation
Open

HDDS-15740. Validate partNumber on GetObject and return InvalidPart for out-of-range parts#10670
rich7420 wants to merge 1 commit into
apache:masterfrom
rich7420:HDDS-partnumber-validation

Conversation

@rich7420

@rich7420 rich7420 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

When an S3 GetObject/HeadObject request carries a partNumber that does not
exist in the object, Ozone silently returned an empty (0-byte) body with a 200
response, instead of rejecting the request. AWS S3 returns 400 InvalidPart in
this case.

This PR validates the requested part number in the OM read path
(KeyManagerImpl.readKeyInfo):

  • Multipart key — filter the key's blocks by the requested part number. If no
    block matches, the part does not exist, so throw OMException(INVALID_PART).
    This is done by presence (empty filtered list), not by a part count, so it
    correctly handles objects completed with non-contiguous part numbers
    (e.g. parts {1, 3} where part 3 is valid but part 2 is not).
  • Non-multipart keypartNumber == 1 returns the whole object (AWS
    semantics); any partNumber > 1 is out of range and throws
    OMException(INVALID_PART).

INVALID_PART is already mapped to the S3 InvalidPart error (400) by
S3ErrorTable, so no gateway/wire changes are needed.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-15740

How was this patch tested?

https://github.com/rich7420/ozone/actions/runs/28732155743

…or out-of-range parts

Validate the requested partNumber against the object's actual part count in the
OM read path (KeyManagerImpl.readKeyInfo):
- Multipart key: throw InvalidPart when partNumber exceeds the number of parts
  (previously returned an empty 0-byte HTTP 200).
- Non-multipart key: throw InvalidPart when partNumber > 1 (previously the
  partNumber was silently ignored and the whole object returned); partNumber == 1
  still returns the whole object.

Update existing tests that asserted the old (0-byte) out-of-range behavior to
expect InvalidPart: TestKeyManagerImpl, TestOzoneClientMultipartUploadWithFSO,
AbstractS3SDKV1Tests, and the objectputget.robot acceptance test.

Fixes ceph s3-tests test_multipart_get_part, test_multipart_single_get_part,
test_non_multipart_get_part, test_multipart_sse_c_get_part and
test_non_multipart_sse_c_get_part.
@jojochuang jojochuang requested a review from spacemonkd July 6, 2026 16:18
@adoroszlai adoroszlai added the s3 S3 Gateway label Jul 8, 2026
@hevinhsu

hevinhsu commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @rich7420 for the patch!
As AWS SDK for Java v1 is deprecated, I think it would be good to also add an integration test in AbstractS3SDKV2Tests to cover this behavior.

@sreejasahithi sreejasahithi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @rich7420 for the PR
Could you please add a test for the non-contiguous part numbers case as well.
As testGetNotExistedPart covers part 4 on a contiguous 1–3 part object (beyond max).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s3 S3 Gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants