[ 
https://issues.apache.org/jira/browse/PARQUET-2247?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17690110#comment-17690110
 ] 

ASF GitHub Bot commented on PARQUET-2247:
-----------------------------------------

wgtmac commented on code in PR #1031:
URL: https://github.com/apache/parquet-mr/pull/1031#discussion_r1109248942


##########
parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java:
##########
@@ -205,6 +206,12 @@ public void write(byte b[], int off, int len) {
       throw new IndexOutOfBoundsException(
           String.format("Given byte array of size %d, with requested 
length(%d) and offset(%d)", b.length, len, off));
     }
+    int targetBytesUsed = bytesUsed + len;

Review Comment:
   Thanks for the change!
   
   What about using `bytesUsed = Math.addExact(bytesUsed, len)`. It is 
available in java8 and looks more elegant to throw ArithmeticException by 
itself.
   
   
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#addExact(int,int)





> Fail-fast if CapacityByteArrayOutputStream write overflow
> ---------------------------------------------------------
>
>                 Key: PARQUET-2247
>                 URL: https://issues.apache.org/jira/browse/PARQUET-2247
>             Project: Parquet
>          Issue Type: Bug
>          Components: parquet-mr
>            Reporter: dzcxzl
>            Priority: Critical
>
> The bytesUsed of CapacityByteArrayOutputStream may overflow when writing some 
> large byte data, resulting in parquet file write corruption.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to