Copilot commented on code in PR #11136:
URL: https://github.com/apache/ozone/pull/11136#discussion_r3877580823
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpointStreaming.java:
##########
@@ -189,8 +196,8 @@ public static long copyKeyWithStream(
long metadataLatencyNs =
METRICS.updateCopyKeyMetadataStats(startNanos);
writeLen = writeGuard.copyFrom(body, bufferSize);
- String eTag =
DatatypeConverter.printHexBinary(body.getMessageDigest().digest())
- .toLowerCase();
+ String eTag = reusedETag != null ? reusedETag
+ : DatatypeConverter.printHexBinary(((DigestInputStream)
body).getMessageDigest().digest()).toLowerCase();
perf.appendMetaLatencyNanos(metadataLatencyNs);
writeGuard.getMetadata().put(OzoneConsts.ETAG, eTag);
Review Comment:
`copyKeyWithStream(...)` now takes an `InputStream`, but when `reusedETag`
is null it unconditionally casts `body` to `DigestInputStream` to compute the
MD5. This can throw `ClassCastException` if the method is ever called with a
non-digest stream; add an explicit contract check (or keep the digest parameter
typed as `DigestInputStream`).
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -1115,8 +1121,9 @@ srcKeyLen > getDatastreamMinLength()) {
getMetrics().updateCopyKeyMetadataStats(startNanos);
perf.appendMetaLatencyNanos(metadataLatencyNs);
copyLength = dest.copyFrom(src, getIOBufferSize(expectedLength));
- String md5Hash =
DatatypeConverter.printHexBinary(src.getMessageDigest().digest()).toLowerCase();
- dest.getMetadata().put(OzoneConsts.ETAG, md5Hash);
+ String eTag = reusedETag != null ? reusedETag
+ : DatatypeConverter.printHexBinary(((DigestInputStream)
src).getMessageDigest().digest()).toLowerCase();
+ dest.getMetadata().put(OzoneConsts.ETAG, eTag);
Review Comment:
`copy(...)` now accepts an `InputStream`, but when `reusedETag` is null it
unconditionally casts `src` to `DigestInputStream`. This makes the method
contract type-unsafe and can fail with a `ClassCastException` if a future
caller passes a non-digest stream while expecting recomputation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]