Skip to content

HDDS-15348. OmMultipartPartKeyCodec should not use UTF8.decode(..)#10347

Open
Russole wants to merge 3 commits into
apache:masterfrom
Russole:HDDS-15348
Open

HDDS-15348. OmMultipartPartKeyCodec should not use UTF8.decode(..)#10347
Russole wants to merge 3 commits into
apache:masterfrom
Russole:HDDS-15348

Conversation

@Russole
Copy link
Copy Markdown
Contributor

@Russole Russole commented May 23, 2026

What changes were proposed in this pull request?

  • Replace StandardCharsets.UTF_8.decode(...) in OmMultipartPartKey with StringCodec for decoding the persisted upload ID bytes.
  • The round-trip UTF-8 validation is needed because 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.
  • Add a unit test to verify malformed UTF-8 upload IDs throw IllegalArgumentException.

What is the link to the Apache JIRA

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

How was this patch tested?

@Russole Russole requested a review from szetszwo May 23, 2026 09:12
@ivandika3 ivandika3 requested a review from spacemonkd May 23, 2026 11:39
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");
}
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.

@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.

@Russole Russole requested a review from szetszwo May 27, 2026 17:43
Copy link
Copy Markdown
Contributor

@szetszwo szetszwo left a comment

Choose a reason for hiding this comment

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

@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.

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.

2 participants