This is an automated email from the ASF dual-hosted git repository.
FrankChen021 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 1f68c5e1687 fix: harden arithmetic and bounds checks (#19818)
1f68c5e1687 is described below
commit 1f68c5e16870f40b57fa78ad12e3cff271efc2b0
Author: Frank Chen <[email protected]>
AuthorDate: Thu Sep 10 14:05:51 2026 +0800
fix: harden arithmetic and bounds checks (#19818)
* Fix CodeQL arithmetic and bounds warnings
* fix: validate serialized buffer lengths
* fix: complete serialized buffer bounds validation
* style: fix bounds test license header
* fix: validate compressed block buffer bounds
* test: migrate bounds tests to JUnit 5
* test: address review feedback
* test: use Druid string formatting
---
.../apache/druid/storage/aliyun/OssTaskLogsTest.java | 3 ++-
.../spectator/histogram/SpectatorHistogramTest.java | 14 +++++++-------
.../google/GoogleCloudStorageInputSourceTest.java | 4 ++--
.../apache/druid/data/input/MapPopulatorTest.java | 2 +-
.../org/apache/druid/storage/s3/S3TaskLogsTest.java | 3 ++-
.../s3/output/RetryableS3OutputStreamTest.java | 6 +++---
.../SeekableStreamSupervisorStateManagerTest.java | 2 +-
.../BitmapOperationAgainstConsecutiveRunsTest.java | 3 ++-
.../druid/java/util/common/CompressionUtilsTest.java | 12 ++++++------
.../SerializablePairLongStringBufferStoreTest.java | 3 ---
.../druid/query/scan/ScanQueryRunnerFactoryTest.java | 4 ++--
.../druid/segment/data/SafeWritableMemoryTest.java | 20 ++++++++++----------
...mpressedVSizeColumnarMultiIntsSerializerTest.java | 5 +++--
.../segment/serde/HyperUniquesSerdeForTest.java | 5 +++++
.../druid/segment/loading/StorageLocationTest.java | 2 +-
15 files changed, 47 insertions(+), 41 deletions(-)
diff --git
a/extensions-contrib/aliyun-oss-extensions/src/test/java/org/apache/druid/storage/aliyun/OssTaskLogsTest.java
b/extensions-contrib/aliyun-oss-extensions/src/test/java/org/apache/druid/storage/aliyun/OssTaskLogsTest.java
index 062c46ef30d..e84193c5b78 100644
---
a/extensions-contrib/aliyun-oss-extensions/src/test/java/org/apache/druid/storage/aliyun/OssTaskLogsTest.java
+++
b/extensions-contrib/aliyun-oss-extensions/src/test/java/org/apache/druid/storage/aliyun/OssTaskLogsTest.java
@@ -348,7 +348,8 @@ public class OssTaskLogsTest extends EasyMockSupport
EasyMock.replay(ossClient);
OssTaskLogs ossTaskLogs = getOssTaskLogs();
- Optional<InputStream> inputStreamOptional =
ossTaskLogs.streamTaskLog(KEY_1, -1 * (LOG_CONTENTS.length() - 1));
+ final Optional<InputStream> inputStreamOptional =
+ ossTaskLogs.streamTaskLog(KEY_1, 1L - LOG_CONTENTS.length());
final String taskLogs;
try (final BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStreamOptional.get(),
StandardCharsets.UTF_8))) {
diff --git
a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java
b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java
index 8ca91dcd07c..1f935eed695 100644
---
a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java
+++
b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java
@@ -59,7 +59,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
int valSize = 0;
- Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should
compact small values within key bytes");
+ Assertions.assertEquals(5L * (keySize + valSize), bytes.length, "Should
compact small values within key bytes");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(1L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -88,7 +88,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
int valSize = Byte.BYTES;
- Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should
compact small values to a byte");
+ Assertions.assertEquals(5L * (keySize + valSize), bytes.length, "Should
compact small values to a byte");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(64L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -117,7 +117,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
int valSize = Short.BYTES;
- Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should
compact medium values to short");
+ Assertions.assertEquals(5L * (keySize + valSize), bytes.length, "Should
compact medium values to short");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(512L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -146,7 +146,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
int valSize = Integer.BYTES;
- Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should
compact larger values to integer");
+ Assertions.assertEquals(5L * (keySize + valSize), bytes.length, "Should
compact larger values to integer");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(100000L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -175,7 +175,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
int valSize = Long.BYTES;
- Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should not
compact larger values");
+ Assertions.assertEquals(5L * (keySize + valSize), bytes.length, "Should
not compact larger values");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(10000000000L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -203,7 +203,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
- Assertions.assertEquals((5 * keySize) + 0 + 2 + 4 + 8 + 8, bytes.length,
"Should not compact larger values");
+ Assertions.assertEquals((5L * keySize) + 0 + 2 + 4 + 8 + 8, bytes.length,
"Should not compact larger values");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(1L,
deserialized.get(PercentileBuckets.indexOf(10)));
@@ -234,7 +234,7 @@ public class SpectatorHistogramTest
byte[] bytes = histogram.toBytes();
int keySize = Short.BYTES;
- Assertions.assertEquals((8 * keySize) + 0 + 1 + 1 + 2 + 2 + 4 + 4 + 8,
bytes.length, "Should compact");
+ Assertions.assertEquals((8L * keySize) + 0 + 1 + 1 + 2 + 2 + 4 + 4 + 8,
bytes.length, "Should compact");
SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes);
Assertions.assertEquals(63L, deserialized.get(6));
diff --git
a/extensions-core/google-extensions/src/test/java/org/apache/druid/data/input/google/GoogleCloudStorageInputSourceTest.java
b/extensions-core/google-extensions/src/test/java/org/apache/druid/data/input/google/GoogleCloudStorageInputSourceTest.java
index 626c4e816b7..c84f39db42b 100644
---
a/extensions-core/google-extensions/src/test/java/org/apache/druid/data/input/google/GoogleCloudStorageInputSourceTest.java
+++
b/extensions-core/google-extensions/src/test/java/org/apache/druid/data/input/google/GoogleCloudStorageInputSourceTest.java
@@ -418,7 +418,7 @@ public class GoogleCloudStorageInputSourceTest extends
InitializedNullHandlingTe
Assertions.assertEquals("hello", nextRow.getDimension("dim1").get(0));
Assertions.assertEquals("world", nextRow.getDimension("dim2").get(0));
}
- Assertions.assertEquals(2 * CONTENT.length,
inputStats.getProcessedBytes());
+ Assertions.assertEquals(2L * CONTENT.length,
inputStats.getProcessedBytes());
}
@Test
@@ -465,7 +465,7 @@ public class GoogleCloudStorageInputSourceTest extends
InitializedNullHandlingTe
Assertions.assertEquals("hello", nextRow.getDimension("dim1").get(0));
Assertions.assertEquals("world", nextRow.getDimension("dim2").get(0));
}
- Assertions.assertEquals(2 * CONTENT.length,
inputStats.getProcessedBytes());
+ Assertions.assertEquals(2L * CONTENT.length,
inputStats.getProcessedBytes());
}
@Test
diff --git
a/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/data/input/MapPopulatorTest.java
b/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/data/input/MapPopulatorTest.java
index c72815122fd..822e98de135 100644
---
a/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/data/input/MapPopulatorTest.java
+++
b/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/data/input/MapPopulatorTest.java
@@ -39,7 +39,7 @@ public class MapPopulatorTest
public void test_getByteLengthOfObject_string_stringLength()
{
String o = "string";
- Assertions.assertEquals((o.length() * Character.BYTES) + 40,
MapPopulator.getByteLengthOfObject(o));
+ Assertions.assertEquals(((long) o.length() * Character.BYTES) + 40,
MapPopulator.getByteLengthOfObject(o));
}
@Test
diff --git
a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java
b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java
index 45d0be3ee95..769f824f285 100644
---
a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java
+++
b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/S3TaskLogsTest.java
@@ -516,7 +516,8 @@ public class S3TaskLogsTest extends EasyMockSupport
S3TaskLogs s3TaskLogs = getS3TaskLogs();
- Optional<InputStream> inputStreamOptional =
s3TaskLogs.streamTaskLog(KEY_1, -1 * (LOG_CONTENTS.length() - 1));
+ final Optional<InputStream> inputStreamOptional =
+ s3TaskLogs.streamTaskLog(KEY_1, 1L - LOG_CONTENTS.length());
final String taskLogs;
try (final BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStreamOptional.get(),
StandardCharsets.UTF_8))) {
diff --git
a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/output/RetryableS3OutputStreamTest.java
b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/output/RetryableS3OutputStreamTest.java
index d3116dd9933..495f7419dd1 100644
---
a/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/output/RetryableS3OutputStreamTest.java
+++
b/extensions-core/s3-extensions/src/test/java/org/apache/druid/storage/s3/output/RetryableS3OutputStreamTest.java
@@ -126,7 +126,7 @@ public class RetryableS3OutputStreamTest
}
// each chunk is 10 bytes, so there should be 10 chunks.
Assertions.assertEquals(10, s3.partRequests.size());
- s3.assertCompleted(chunkSize, Integer.BYTES * 25);
+ s3.assertCompleted(chunkSize, Integer.BYTES * 25L);
}
@Test
@@ -144,7 +144,7 @@ public class RetryableS3OutputStreamTest
}
// each chunk 10 bytes, so there should be 2 chunks.
Assertions.assertEquals(2, s3.partRequests.size());
- s3.assertCompleted(chunkSize, Integer.BYTES * 3);
+ s3.assertCompleted(chunkSize, Integer.BYTES * 3L);
}
@Test
@@ -195,7 +195,7 @@ public class RetryableS3OutputStreamTest
}
// each chunk is 10 bytes, so there should be 10 chunks.
Assertions.assertEquals(10, s3.partRequests.size());
- s3.assertCompleted(chunkSize, Integer.BYTES * 25);
+ s3.assertCompleted(chunkSize, Integer.BYTES * 25L);
}
/**
diff --git
a/indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorStateManagerTest.java
b/indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorStateManagerTest.java
index f0b0bde2422..46b11af4f4b 100644
---
a/indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorStateManagerTest.java
+++
b/indexing-service/src/test/java/org/apache/druid/indexing/seekablestream/supervisor/SeekableStreamSupervisorStateManagerTest.java
@@ -235,7 +235,7 @@ public class SeekableStreamSupervisorStateManagerTest
stateManager.markRunFinished(); // clean run
Assertions.assertEquals(BasicState.RUNNING,
stateManager.getSupervisorState());
Assertions.assertEquals(BasicState.RUNNING,
stateManager.getSupervisorState().getBasicState());
- Assertions.assertEquals(j * (config.getUnhealthinessThreshold() - 1),
stateManager.getExceptionEvents().size());
+ Assertions.assertEquals((long) j * (config.getUnhealthinessThreshold() -
1), stateManager.getExceptionEvents().size());
}
}
diff --git
a/processing/src/test/java/org/apache/druid/collections/bitmap/BitmapOperationAgainstConsecutiveRunsTest.java
b/processing/src/test/java/org/apache/druid/collections/bitmap/BitmapOperationAgainstConsecutiveRunsTest.java
index 67e60f5d7cb..d1e26d5adc2 100644
---
a/processing/src/test/java/org/apache/druid/collections/bitmap/BitmapOperationAgainstConsecutiveRunsTest.java
+++
b/processing/src/test/java/org/apache/druid/collections/bitmap/BitmapOperationAgainstConsecutiveRunsTest.java
@@ -58,7 +58,8 @@ public class BitmapOperationAgainstConsecutiveRunsTest
extends BitmapOperationTe
}
}
minIntersection = MIN_INTERSECT;
- for (int k = BITMAP_LENGTH / 2; k < BITMAP_LENGTH / 2 + minIntersection;
++k) {
+ final int minimumIntersection = Math.toIntExact(minIntersection);
+ for (int k = BITMAP_LENGTH / 2; k < BITMAP_LENGTH / 2 +
minimumIntersection; ++k) {
c.add(k);
r.add(k);
expectedUnion.set(k);
diff --git
a/processing/src/test/java/org/apache/druid/java/util/common/CompressionUtilsTest.java
b/processing/src/test/java/org/apache/druid/java/util/common/CompressionUtilsTest.java
index 71348bbd575..5af2e6e912e 100644
---
a/processing/src/test/java/org/apache/druid/java/util/common/CompressionUtilsTest.java
+++
b/processing/src/test/java/org/apache/druid/java/util/common/CompressionUtilsTest.java
@@ -644,7 +644,7 @@ public class CompressionUtilsTest
)
);
}
- Assertions.assertEquals((long) GZ_BYTES.length * 3, testFile.length());
+ Assertions.assertEquals(3L * GZ_BYTES.length, testFile.length());
try (InputStream inputStream = new ZeroRemainingInputStream(new
FileInputStream(testFile))) {
for (int i = 0; i < 3; ++i) {
final byte[] bytes = new byte[GZ_BYTES.length];
@@ -678,17 +678,17 @@ public class CompressionUtilsTest
}
};
- Assertions.assertEquals((long) (EXPECTED.length * 3),
CompressionUtils.gunzip(inputStreamFactory, testFile).size());
+ Assertions.assertEquals(3L * EXPECTED.length,
CompressionUtils.gunzip(inputStreamFactory, testFile).size());
try (final InputStream inputStream = new FileInputStream(testFile)) {
try (final ByteArrayOutputStream outputStream = new
ByteArrayOutputStream(EXPECTED.length * 3)) {
Assertions.assertEquals(
- EXPECTED.length * 3,
+ 3L * EXPECTED.length,
ByteStreams.copy(inputStream, outputStream),
"Read terminated too soon"
);
final byte[] found = outputStream.toByteArray();
- Assertions.assertEquals(EXPECTED.length * 3, found.length);
+ Assertions.assertEquals(3L * EXPECTED.length, found.length);
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 0, EXPECTED.length * 1));
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 1, EXPECTED.length * 2));
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 2, EXPECTED.length * 3));
@@ -707,7 +707,7 @@ public class CompressionUtilsTest
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(EXPECTED.length
* 3)) {
Assertions.assertEquals(
- EXPECTED.length * 3,
+ 3L * EXPECTED.length,
CompressionUtils.gunzip(
new ZeroRemainingInputStream(
new ByteArrayInputStream(tripleGzByteStream.toByteArray())
@@ -715,7 +715,7 @@ public class CompressionUtilsTest
)
);
final byte[] found = bos.toByteArray();
- Assertions.assertEquals(EXPECTED.length * 3, found.length);
+ Assertions.assertEquals(3L * EXPECTED.length, found.length);
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 0, EXPECTED.length * 1));
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 1, EXPECTED.length * 2));
Assertions.assertArrayEquals(EXPECTED, Arrays.copyOfRange(found,
EXPECTED.length * 2, EXPECTED.length * 3));
diff --git
a/processing/src/test/java/org/apache/druid/query/aggregation/SerializablePairLongStringBufferStoreTest.java
b/processing/src/test/java/org/apache/druid/query/aggregation/SerializablePairLongStringBufferStoreTest.java
index eda20be7bc5..3c110155f46 100644
---
a/processing/src/test/java/org/apache/druid/query/aggregation/SerializablePairLongStringBufferStoreTest.java
+++
b/processing/src/test/java/org/apache/druid/query/aggregation/SerializablePairLongStringBufferStoreTest.java
@@ -213,7 +213,6 @@ public class SerializablePairLongStringBufferStoreTest
int maxStringSize = 1024 * 1024;
int minStringSize = 1024;
List<SerializablePairLongString> input = new ArrayList<>(rowCount);
- int totalCount = 0;
for (int i = 0; i < rowCount; i++) {
long longValue = random.nextLong();
@@ -221,8 +220,6 @@ public class SerializablePairLongStringBufferStoreTest
new SerializablePairLongString(longValue,
RandomStringUtils.randomAlphabetic(minStringSize, maxStringSize));
input.add(value);
- totalCount += longValue;
- totalCount = Math.max(totalCount, 0);
bufferStore.store(value);
}
diff --git
a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java
b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java
index 887634333bf..c7031f636a3 100644
---
a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java
+++
b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java
@@ -262,7 +262,7 @@ public class ScanQueryRunnerFactoryTest
}
// check total # of rows <= limit
- Assertions.assertTrue(output.size() <= query.getScanRowsLimit());
+ Assertions.assertTrue((long) output.size() <= query.getScanRowsLimit());
// check ordering is correct
for (int i = 1; i < output.size(); i++) {
@@ -276,7 +276,7 @@ public class ScanQueryRunnerFactoryTest
}
// check the values are correct
- for (int i = 0; i < query.getScanRowsLimit() && i < output.size(); i++) {
+ for (int i = 0; (long) i < query.getScanRowsLimit() && i <
output.size(); i++) {
Assertions.assertEquals((long) expectedEventTimestamps.get(i),
output.get(i).getFirstEventTimestamp(resultFormat));
}
}
diff --git
a/processing/src/test/java/org/apache/druid/segment/data/SafeWritableMemoryTest.java
b/processing/src/test/java/org/apache/druid/segment/data/SafeWritableMemoryTest.java
index 7a372bfcea9..3bed40b63bd 100644
---
a/processing/src/test/java/org/apache/druid/segment/data/SafeWritableMemoryTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/data/SafeWritableMemoryTest.java
@@ -107,7 +107,7 @@ public class SafeWritableMemoryTest
memory.putDoubleArray(100L, double1, 0, 1);
memory.putDoubleArray(100L + Double.BYTES, double1, 1, 3);
memory.getDoubleArray(100L, double2, 0, 2);
- memory.getDoubleArray(100L + (2 * Double.BYTES), double2, 2, 2);
+ memory.getDoubleArray(100L + (2L * Double.BYTES), double2, 2, 2);
for (int i = 0; i < double1.length; i++) {
Assertions.assertEquals(double1[i], double2[i], 0.0);
}
@@ -117,7 +117,7 @@ public class SafeWritableMemoryTest
memory.putFloatArray(100L, float1, 0, 1);
memory.putFloatArray(100L + Float.BYTES, float1, 1, 3);
memory.getFloatArray(100L, float2, 0, 2);
- memory.getFloatArray(100L + (2 * Float.BYTES), float2, 2, 2);
+ memory.getFloatArray(100L + (2L * Float.BYTES), float2, 2, 2);
for (int i = 0; i < float1.length; i++) {
Assertions.assertEquals(float1[i], float2[i], 0.0);
}
@@ -127,7 +127,7 @@ public class SafeWritableMemoryTest
memory.putIntArray(100L, ints1, 0, 1);
memory.putIntArray(100L + Integer.BYTES, ints1, 1, 3);
memory.getIntArray(100L, ints2, 0, 2);
- memory.getIntArray(100L + (2 * Integer.BYTES), ints2, 2, 2);
+ memory.getIntArray(100L + (2L * Integer.BYTES), ints2, 2, 2);
Assertions.assertArrayEquals(ints1, ints2);
final long[] longs1 = new long[]{1L, -2L, 3L, -14L};
@@ -135,7 +135,7 @@ public class SafeWritableMemoryTest
memory.putLongArray(100L, longs1, 0, 1);
memory.putLongArray(100L + Long.BYTES, longs1, 1, 3);
memory.getLongArray(100L, longs2, 0, 2);
- memory.getLongArray(100L + (2 * Long.BYTES), longs2, 2, 2);
+ memory.getLongArray(100L + (2L * Long.BYTES), longs2, 2, 2);
Assertions.assertArrayEquals(longs1, longs2);
final short[] shorts1 = new short[]{1, -2, 3, -14};
@@ -143,7 +143,7 @@ public class SafeWritableMemoryTest
memory.putShortArray(100L, shorts1, 0, 1);
memory.putShortArray(100L + Short.BYTES, shorts1, 1, 3);
memory.getShortArray(100L, shorts2, 0, 2);
- memory.getShortArray(100L + (2 * Short.BYTES), shorts2, 2, 2);
+ memory.getShortArray(100L + (2L * Short.BYTES), shorts2, 2, 2);
Assertions.assertArrayEquals(shorts1, shorts2);
}
@@ -153,15 +153,15 @@ public class SafeWritableMemoryTest
final byte theByte = 0x01;
final byte anotherByte = 0x02;
final WritableMemory memory = getMemory();
- final int halfWay = (int) (memory.getCapacity() / 2);
+ final long halfWay = memory.getCapacity() / 2;
memory.fill(theByte);
- for (int i = 0; i < memory.getCapacity(); i++) {
+ for (long i = 0; i < memory.getCapacity(); i++) {
Assertions.assertEquals(theByte, memory.getByte(i));
}
memory.fill(halfWay, memory.getCapacity() - halfWay, anotherByte);
- for (int i = 0; i < memory.getCapacity(); i++) {
+ for (long i = 0; i < memory.getCapacity(); i++) {
if (i < halfWay) {
Assertions.assertEquals(theByte, memory.getByte(i));
} else {
@@ -170,7 +170,7 @@ public class SafeWritableMemoryTest
}
memory.clear(halfWay, memory.getCapacity() - halfWay);
- for (int i = 0; i < memory.getCapacity(); i++) {
+ for (long i = 0; i < memory.getCapacity(); i++) {
if (i < halfWay) {
Assertions.assertEquals(theByte, memory.getByte(i));
} else {
@@ -184,7 +184,7 @@ public class SafeWritableMemoryTest
Assertions.assertEquals(anotherByte, memory.getByte(halfWay - 1));
memory.clear();
- for (int i = 0; i < memory.getCapacity(); i++) {
+ for (long i = 0; i < memory.getCapacity(); i++) {
Assertions.assertEquals(0, memory.getByte(i));
}
}
diff --git
a/processing/src/test/java/org/apache/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java
b/processing/src/test/java/org/apache/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java
index 47af1f318a3..e0df6dcabaa 100644
---
a/processing/src/test/java/org/apache/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java
@@ -467,9 +467,10 @@ public class
V3CompressedVSizeColumnarMultiIntsSerializerTest
V3CompressedVSizeColumnarMultiIntsSupplier supplierFromByteBuffer =
V3CompressedVSizeColumnarMultiIntsSupplier.fromByteBuffer(mapper.mapFile("test"),
byteOrder, mapper);
ColumnarMultiInts columnarMultiInts = supplierFromByteBuffer.get();
- Assertions.assertEquals(columnarMultiInts.size(), numRows);
+ final int rowCount = Math.toIntExact(numRows);
+ Assertions.assertEquals(columnarMultiInts.size(), rowCount);
Random verifier = new Random(0);
- for (int i = 0; i < numRows; ++i) {
+ for (int i = 0; i < rowCount; ++i) {
IndexedInts subVals = columnarMultiInts.get(i);
int[] expected = generateRow(verifier, maxValue, maxValuesPerRow);
Assertions.assertEquals(subVals.size(), expected.length);
diff --git
a/processing/src/test/java/org/apache/druid/segment/serde/HyperUniquesSerdeForTest.java
b/processing/src/test/java/org/apache/druid/segment/serde/HyperUniquesSerdeForTest.java
index 99f3c24a54a..34b8d2fe791 100644
---
a/processing/src/test/java/org/apache/druid/segment/serde/HyperUniquesSerdeForTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/serde/HyperUniquesSerdeForTest.java
@@ -116,6 +116,11 @@ public class HyperUniquesSerdeForTest extends
ComplexMetricSerde
public HyperLogLogCollector fromByteBuffer(ByteBuffer buffer, int
numBytes)
{
final ByteBuffer readOnlyBuffer = buffer.asReadOnlyBuffer();
+ if (numBytes < 0 || numBytes > readOnlyBuffer.remaining()) {
+ throw new IllegalArgumentException(
+ StringUtils.format("Invalid numBytes[%d] for buffer
remaining[%d]", numBytes, readOnlyBuffer.remaining())
+ );
+ }
readOnlyBuffer.limit(readOnlyBuffer.position() + numBytes);
return HyperLogLogCollector.makeCollector(readOnlyBuffer);
}
diff --git
a/server/src/test/java/org/apache/druid/segment/loading/StorageLocationTest.java
b/server/src/test/java/org/apache/druid/segment/loading/StorageLocationTest.java
index 23b89108e08..159982c662f 100644
---
a/server/src/test/java/org/apache/druid/segment/loading/StorageLocationTest.java
+++
b/server/src/test/java/org/apache/druid/segment/loading/StorageLocationTest.java
@@ -804,7 +804,7 @@ class StorageLocationTest
private void verifyLoc(long maxSize, StorageLocation loc)
{
Assertions.assertEquals(maxSize, loc.availableSizeBytes());
- for (int i = 0; i <= maxSize; ++i) {
+ for (long i = 0; i <= maxSize; ++i) {
Assertions.assertTrue(loc.canHandle(makeSegmentEntry("2013/2014",
i)).isSuccess(), String.valueOf(i));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]