You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ho...@apache.org on 2026/09/03 03:48:20 UTC
(spark) branch master updated: [CORE][MINOR] Validate array counts against received bytes in shuffle fetch decoders
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 96877933458a [CORE][MINOR] Validate array counts against received bytes in shuffle fetch decoders
96877933458a is described below
commit 96877933458a7f0eb989677bd07ea4513993a69d
Author: Holden Karau <ho...@snowflake.com>
AuthorDate: Mon Aug 31 21:24:11 2026 +0000
[CORE][MINOR] Validate array counts against received bytes in shuffle fetch decoders
FetchShuffleBlocks and FetchShuffleBlockChunks decode an outer element
count and eagerly allocate a 2D array of that size. Check the count
against the bytes actually received before allocating, mirroring the
bounds checks Encoders already applies: each inner group carries its own
4-byte length prefix, so a valid count never exceeds readableBytes() / 4.
Co-authored-by: Cursor <cu...@cursor.com>
Co-Authored-By: Holden Karau <ho...@pigscanfly.ca>
---
.../network/shuffle/protocol/FetchShuffleBlockChunks.java | 4 ++++
.../network/shuffle/protocol/FetchShuffleBlocks.java | 4 ++++
.../shuffle/protocol/FetchShuffleBlockChunksSuite.java | 15 +++++++++++++++
.../network/shuffle/protocol/FetchShuffleBlocksSuite.java | 14 ++++++++++++++
4 files changed, 37 insertions(+)
diff --git a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunks.java b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunks.java
index a6e1ce374b07..bd4d26c0daf6 100644
--- a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunks.java
+++ b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunks.java
@@ -18,6 +18,7 @@
package org.apache.spark.network.shuffle.protocol;
import java.util.Arrays;
+import java.util.Objects;
import io.netty.buffer.ByteBuf;
@@ -130,6 +131,9 @@ public class FetchShuffleBlockChunks extends AbstractFetchShuffleBlocks {
int shuffleMergeId = buf.readInt();
int[] reduceIds = Encoders.IntArrays.decode(buf);
int chunkIdsLen = buf.readInt();
+ // The divisor 4 is the minimum on-wire size of one element, since each chunk-id group
+ // is prefixed with its own 4-byte length.
+ Objects.checkFromIndexSize(0, chunkIdsLen, buf.readableBytes() / 4);
int[][] chunkIds = new int[chunkIdsLen][];
for (int i = 0; i < chunkIdsLen; i++) {
chunkIds[i] = Encoders.IntArrays.decode(buf);
diff --git a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocks.java b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocks.java
index 686207767ca1..075f7f76c060 100644
--- a/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocks.java
+++ b/common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocks.java
@@ -18,6 +18,7 @@
package org.apache.spark.network.shuffle.protocol;
import java.util.Arrays;
+import java.util.Objects;
import io.netty.buffer.ByteBuf;
@@ -130,6 +131,9 @@ public class FetchShuffleBlocks extends AbstractFetchShuffleBlocks {
int shuffleId = buf.readInt();
long[] mapIds = Encoders.LongArrays.decode(buf);
int reduceIdsSize = buf.readInt();
+ // The divisor 4 is the minimum on-wire size of one element, since each reduce-id group
+ // is prefixed with its own 4-byte length.
+ Objects.checkFromIndexSize(0, reduceIdsSize, buf.readableBytes() / 4);
int[][] reduceIds = new int[reduceIdsSize][];
for (int i = 0; i < reduceIdsSize; i++) {
reduceIds[i] = Encoders.IntArrays.decode(buf);
diff --git a/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunksSuite.java b/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunksSuite.java
index 943ede03def4..2ff97e842ac5 100644
--- a/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunksSuite.java
+++ b/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlockChunksSuite.java
@@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
+import org.apache.spark.network.protocol.Encoders;
+
public class FetchShuffleBlockChunksSuite {
@Test
@@ -39,4 +41,17 @@ public class FetchShuffleBlockChunksSuite {
FetchShuffleBlockChunks decoded = FetchShuffleBlockChunks.decode(buf);
assertEquals(shuffleBlockChunks, decoded);
}
+
+ @Test
+ public void testDecodeRejectsCountExceedingReceivedBytes() {
+ // Decode must reject the count rather than allocate an array of the claimed size.
+ ByteBuf buf = Unpooled.buffer(64);
+ Encoders.Strings.encode(buf, "app0");
+ Encoders.Strings.encode(buf, "exec1");
+ buf.writeInt(0); // shuffleId
+ buf.writeInt(0); // shuffleMergeId
+ Encoders.IntArrays.encode(buf, new int[] {0});
+ buf.writeInt(Integer.MAX_VALUE); // chunkIds count
+ assertThrows(IndexOutOfBoundsException.class, () -> FetchShuffleBlockChunks.decode(buf));
+ }
}
diff --git a/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocksSuite.java b/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocksSuite.java
index 188d745f6046..c475531df585 100644
--- a/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocksSuite.java
+++ b/common/network-shuffle/src/test/java/org/apache/spark/network/shuffle/protocol/FetchShuffleBlocksSuite.java
@@ -24,6 +24,8 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
+import org.apache.spark.network.protocol.Encoders;
+
public class FetchShuffleBlocksSuite {
@Test
@@ -39,4 +41,16 @@ public class FetchShuffleBlocksSuite {
FetchShuffleBlocks decoded = FetchShuffleBlocks.decode(buf);
assertEquals(fetchShuffleBlocks, decoded);
}
+
+ @Test
+ public void testDecodeRejectsCountExceedingReceivedBytes() {
+ // Decode must reject the count rather than allocate an array of the claimed size.
+ ByteBuf buf = Unpooled.buffer(64);
+ Encoders.Strings.encode(buf, "app0");
+ Encoders.Strings.encode(buf, "exec1");
+ buf.writeInt(0); // shuffleId
+ Encoders.LongArrays.encode(buf, new long[] {0});
+ buf.writeInt(Integer.MAX_VALUE); // reduceIds count
+ assertThrows(IndexOutOfBoundsException.class, () -> FetchShuffleBlocks.decode(buf));
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org