peterxcli commented on code in PR #10078:
URL: https://github.com/apache/ozone/pull/10078#discussion_r3081251665
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Utils.java:
##########
@@ -242,23 +243,34 @@ public static String wrapInQuotes(String value) {
/**
* Validates the Content-MD5 header against the actual MD5 hash.
*
+ * <p>Throws {@link
org.apache.hadoop.ozone.s3.exception.S3ErrorTable#INVALID_DIGEST}
+ * when the Content-MD5 header is absent, contains an invalid Base64 string,
+ * or decodes to a byte array that is not exactly 16 bytes (i.e. not a valid
+ * MD5 digest). Throws
+ * {@link org.apache.hadoop.ozone.s3.exception.S3ErrorTable#BAD_DIGEST}
+ * when the header is well-formed but does not match the computed hash.
+ *
* @param clientMD5 the base64-encoded MD5 from Content-MD5 header
* @param serverMD5 the hex-encoded MD5 hash of the data
* @param resource the resource path for error messages
- * @throws OS3Exception if the MD5 values do not match
+ * @throws OS3Exception if the Content-MD5 is invalid or does not match
*/
public static void validateContentMD5(String clientMD5, String serverMD5,
String resource)
throws OS3Exception {
if (clientMD5 == null) {
- throw newError(BAD_DIGEST, resource);
+ throw newError(INVALID_DIGEST, resource);
}
try {
- if
(!Hex.encodeHexString(Base64.getDecoder().decode(clientMD5)).equals(serverMD5))
{
+ byte[] decoded = Base64.getDecoder().decode(clientMD5);
+ if (decoded.length != 16) {
Review Comment:
should we use regex to validate the decoded? or the byte count is enough and
more efficient?
https://stackoverflow.com/a/21517123.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/util/S3Utils.java:
##########
@@ -242,23 +243,34 @@ public static String wrapInQuotes(String value) {
/**
* Validates the Content-MD5 header against the actual MD5 hash.
*
+ * <p>Throws {@link
org.apache.hadoop.ozone.s3.exception.S3ErrorTable#INVALID_DIGEST}
+ * when the Content-MD5 header is absent, contains an invalid Base64 string,
+ * or decodes to a byte array that is not exactly 16 bytes (i.e. not a valid
+ * MD5 digest). Throws
+ * {@link org.apache.hadoop.ozone.s3.exception.S3ErrorTable#BAD_DIGEST}
+ * when the header is well-formed but does not match the computed hash.
+ *
* @param clientMD5 the base64-encoded MD5 from Content-MD5 header
* @param serverMD5 the hex-encoded MD5 hash of the data
* @param resource the resource path for error messages
- * @throws OS3Exception if the MD5 values do not match
+ * @throws OS3Exception if the Content-MD5 is invalid or does not match
*/
public static void validateContentMD5(String clientMD5, String serverMD5,
String resource)
throws OS3Exception {
if (clientMD5 == null) {
- throw newError(BAD_DIGEST, resource);
+ throw newError(INVALID_DIGEST, resource);
}
try {
- if
(!Hex.encodeHexString(Base64.getDecoder().decode(clientMD5)).equals(serverMD5))
{
+ byte[] decoded = Base64.getDecoder().decode(clientMD5);
+ if (decoded.length != 16) {
Review Comment:
ok i think the byte count check is enough.
--
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]