HDDS-15348. OmMultipartPartKeyCodec should not use UTF8.decode(..)#10347
Open
Russole wants to merge 3 commits into
Open
HDDS-15348. OmMultipartPartKeyCodec should not use UTF8.decode(..)#10347Russole wants to merge 3 commits into
Russole wants to merge 3 commits into
Conversation
szetszwo
reviewed
May 23, 2026
Comment on lines
+191
to
+196
| String uploadId = StringCodec.get().fromPersistedFormat(uploadIdBytes); | ||
| if (!Arrays.equals(uploadIdBytes, | ||
| uploadId.getBytes(StandardCharsets.UTF_8))) { | ||
| throw new IllegalArgumentException( | ||
| "Invalid multipart part key: malformed UTF-8 uploadId"); | ||
| } |
Contributor
There was a problem hiding this comment.
@Russole , thanks for working on this! We should throw CodecException. It needs a new variant of StringCodec. Filed HDDS-15355.
BTW, we should also change the other IllegalArgumentException in OmMultipartPartKeyCodec to CodecException.
szetszwo
reviewed
May 27, 2026
Contributor
szetszwo
left a comment
There was a problem hiding this comment.
@Russole , thanks for the update. The change looks good.
We should also update toCodecBuffer(..) and toPersistedFormat(..) to use StringCodec.getCodecNoFallback() since String.getBytes(..) could replace the unsupported character silently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
StandardCharsets.UTF_8.decode(...)inOmMultipartPartKeywithStringCodecfor decoding the persisted upload ID bytes.StringCodecBase.decode(...)catches strict decoding exceptions and falls back to compatibility decoding, which may use replacement characters. Re-encoding the decoded upload ID and comparing it with the original bytes lets us detect non-lossless decoding and reject malformed UTF-8 input.IllegalArgumentException.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-15348
How was this patch tested?
TestOmMultipartPartKey#testDecodeRejectsMalformedUtf8UploadIdmvn -pl :ozone-common -Dtest=TestOmMultipartPartKey test