yihua commented on code in PR #20321:
URL: https://github.com/apache/hudi/pull/20321#discussion_r4287059784


##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlock.java:
##########
@@ -147,18 +146,24 @@ protected HFileBlock(HFileContext context,
    * Rejects impossible header sizes before they are used to allocate buffers 
or locate content.
    */
   private void validateHeader(byte[] byteBuff, int startOffsetInBuff) {
-    long blockEndInBuff = (long) startOffsetInBuff + HFILEBLOCK_HEADER_SIZE + 
onDiskSizeWithoutHeader;
-    long unpackedSize = (long) HFILEBLOCK_HEADER_SIZE + 
uncompressedSizeWithoutHeader + sizeCheckSum;
+    long onDiskSizeWithHeader = (long) HFILEBLOCK_HEADER_SIZE + 
onDiskSizeWithoutHeader;
+    long blockEndInBuff = startOffsetInBuff + onDiskSizeWithHeader;
+    // Long math, unlike numChecksumBytes, so a corrupt bytesPerChecksum 
cannot throw here
+    long checksumBytes = bytesPerChecksum > 0
+        ? (onDiskSizeWithHeader + bytesPerChecksum - 1) / bytesPerChecksum * 
CHECKSUM_SIZE : 0;

Review Comment:
   Done. `numChecksumBytes` and `numChecksumChunks` now return `long` and 
`validateHeader` calls the helper; the chunk-count overflow guard in 
`numChecksumChunks` is gone since the callers bound the result 
(`validateHeader` on read, the serialized-size check on write), and its test 
went with it. The two `int` call sites narrow after those bounds.



##########
hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileBlock.java:
##########
@@ -137,6 +142,35 @@ protected HFileBlock(HFileContext context,
         this.startOffsetInBuff + HFILEBLOCK_HEADER_SIZE + 
uncompressedSizeWithoutHeader;
   }
 
+  /**
+   * Rejects impossible header sizes before they are used to size checksums, 
allocate buffers or
+   * locate content.
+   */
+  private void validateHeader(byte[] byteBuff, int startOffsetInBuff) {
+    long onDiskSizeWithHeader = (long) HFILEBLOCK_HEADER_SIZE + 
onDiskSizeWithoutHeader;
+    boolean valid = onDiskSizeWithoutHeader >= 0 && 
uncompressedSizeWithoutHeader >= 0

Review Comment:
   That two-stage expression is gone: `validateHeader` is back to the single 
condition it had at review time, with the two new clauses added to it.



-- 
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]

Reply via email to