andygrove commented on code in PR #1422:
URL: https://github.com/apache/arrow-java/pull/1422#discussion_r4447970140


##########
vector/src/main/java/org/apache/arrow/vector/ipc/message/ArrowFieldNode.java:
##########
@@ -31,12 +30,14 @@ public class ArrowFieldNode implements FBSerializable {
    * Constructs a new instance.
    *
    * @param length The number of values written.
-   * @param nullCount The number of null values.
+   * @param nullCount The number of null values, or -1 if unknown.
    */
   public ArrowFieldNode(long length, long nullCount) {
     super();
-    this.length = checkedCastToInt(length);
-    this.nullCount = checkedCastToInt(nullCount);
+    Preconditions.checkArgument(length >= 0, "Expected length >= 0, got %s", 
length);

Review Comment:
   Applied in 23609d6b9: `deserializeRecordBatch(RecordBatch, ArrowBuf)` now 
releases `body` in a `finally`, and `ArrowMessage` is unchanged. Before the 
change I reproduced your repro: `ArrowStreamReader` and `ArrowFileReader` each 
left 8192 bytes allocated for a stream whose node length was patched to -100. 
Both now release everything.
   



##########
vector/src/test/java/org/apache/arrow/vector/ipc/message/TestArrowFieldNode.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.arrow.vector.ipc.message;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+public class TestArrowFieldNode {
+
+  @Test
+  public void testNegativeLengthRejected() {

Review Comment:
   Added `testNegativeNodeLengthDoesNotLeakBody` to `MessageSerializerTest` in 
23609d6b9, plus `testNodeLengthAboveIntRangeDoesNotLeakBody` for the existing 
`IOException` path. Both failed before the fix with the 8-byte body still 
allocated.
   



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