lidavidm commented on code in PR #1422:
URL: https://github.com/apache/arrow-java/pull/1422#discussion_r4434217902
##########
vector/src/main/java/org/apache/arrow/vector/ipc/message/ArrowFieldNode.java:
##########
@@ -35,6 +36,13 @@ public class ArrowFieldNode implements FBSerializable {
*/
public ArrowFieldNode(long length, long nullCount) {
super();
+ // A negative length is never valid and, if accepted, flows unchecked into
buffer size
+ // computations (BitVectorHelper.getValidityBufferSizeFromCount performs
an unsigned shift)
+ // and into ArrowBuf.setOne/setZero, which can corrupt memory when bounds
checking is
+ // disabled. Reject it at this single chokepoint shared by every
deserialization path
+ // (IPC, JSON, C Data). nullCount is intentionally not checked here:
VectorUnloader uses -1
+ // as a sentinel meaning "null count not included".
Review Comment:
I don't know if this comment really helps; at the very least it should be
significantly trimmed. Also we could validate nullCount >= -1 at least?
##########
vector/src/test/java/org/apache/arrow/vector/ipc/message/TestArrowFieldNode.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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() {
+ // A negative length that still fits in an int must be rejected. Left
unchecked it flows into
+ // BitVectorHelper.getValidityBufferSizeFromCount (unsigned shift ->
~512MB) and into
+ // ArrowBuf.setOne(0, length / 8) with a negative length, corrupting
memory when bounds
+ // checking is disabled. See the deserialization paths in
MessageSerializer and JsonFileReader.
Review Comment:
Same here.
--
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]