[GitHub] [parquet-mr] wgtmac commented on a diff in pull request #1032: PARQUET-2164: Check size of buffered data to prevent page data from overflowing
wgtmac commented on code in PR #1032: URL: https://github.com/apache/parquet-mr/pull/1032#discussion_r1115168960 ## parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java: ## @@ -164,6 +164,15 @@ public CapacityByteArrayOutputStream(int initialSlabSize, int maxCapacityHint, B private void addSlab(int minimumSize) { int nextSlabSize; +// check for overflow +try { + Math.addExact(bytesUsed, minimumSize); +} catch (ArithmeticException e) { + // This is interpreted as a request for a value greater than Integer.MAX_VALUE + // We throw OOM because that is what java.io.ByteArrayOutputStream also does + throw new OutOfMemoryError("Size of data exceeded 2GB (" + e.getMessage() + ")"); Review Comment: If we simply do an overflow check here, then the error message should say `Integer.MAX_VALUE` instead of `2GB`. Otherwise, we should explicitly check if the addition result exceeds 2GB. WDYT? -- 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: dev-unsubscr...@parquet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [parquet-mr] wgtmac commented on a diff in pull request #1032: PARQUET-2164: Check size of buffered data to prevent page data from overflowing
wgtmac commented on code in PR #1032: URL: https://github.com/apache/parquet-mr/pull/1032#discussion_r1113858179 ## parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java: ## @@ -164,6 +164,15 @@ public CapacityByteArrayOutputStream(int initialSlabSize, int maxCapacityHint, B private void addSlab(int minimumSize) { int nextSlabSize; +// check for overflow +try { + Math.addExact(bytesUsed, minimumSize); +} catch (ArithmeticException e) { + // This is interpreted as a request for a value greater than Integer.MAX_VALUE + // We throw OOM because that is what java.io.ByteArrayOutputStream also does + throw new OutOfMemoryError("Size of data exceeded 2GB (" + e.getMessage() + ")"); Review Comment: The error message mismatches the check above. Should we compare with 2GB explicitly or change the message? -- 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: dev-unsubscr...@parquet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [parquet-mr] wgtmac commented on a diff in pull request #1032: PARQUET-2164: Check size of buffered data to prevent page data from overflowing
wgtmac commented on code in PR #1032: URL: https://github.com/apache/parquet-mr/pull/1032#discussion_r1112489810 ## parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java: ## @@ -164,6 +164,12 @@ public CapacityByteArrayOutputStream(int initialSlabSize, int maxCapacityHint, B private void addSlab(int minimumSize) { int nextSlabSize; +if (bytesUsed + minimumSize < 0) { Review Comment: nit: replace it with `Math.addExact` to hand over overflow check. Then we get the chance to check the 2GB hard limit before it becoming negative -- 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: dev-unsubscr...@parquet.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org