Skip to content

Commit 05c3b4c

Browse files
committed
fix: Add parameter validation for zero and negative memory sizes
- Add early return in releaseToQuery when sizeInBytes <= 0 to avoid unnecessary operations - Add validation in allocateMemoryBlock to reject zero or negative sizes - Add validation in forceResize to reject negative sizes - These checks prevent invalid parameters that could cause incorrect memory operations
1 parent 85dfc89 commit 05c3b4c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/load/memory/LoadTsFileMemoryManager.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public synchronized long tryAllocateFromQuery(final long sizeInBytes) {
8282
}
8383

8484
public synchronized void releaseToQuery(final long sizeInBytes) {
85+
if (sizeInBytes <= 0) {
86+
return;
87+
}
8588
if (usedMemorySizeInBytes.get() < sizeInBytes) {
8689
LOGGER.error(
8790
"Load: Attempting to release more memory ({}) than allocated ({})",
@@ -96,6 +99,10 @@ public synchronized void releaseToQuery(final long sizeInBytes) {
9699

97100
public synchronized LoadTsFileMemoryBlock allocateMemoryBlock(long sizeInBytes)
98101
throws LoadRuntimeOutOfMemoryException {
102+
if (sizeInBytes <= 0) {
103+
throw new IllegalArgumentException(
104+
String.format("Load: Invalid memory size %d bytes, must be positive", sizeInBytes));
105+
}
99106
try {
100107
forceAllocateFromQuery(sizeInBytes);
101108
if (LOGGER.isDebugEnabled()) {
@@ -120,6 +127,10 @@ public synchronized LoadTsFileMemoryBlock allocateMemoryBlock(long sizeInBytes)
120127
*/
121128
synchronized void forceResize(LoadTsFileMemoryBlock memoryBlock, long newSizeInBytes)
122129
throws LoadRuntimeOutOfMemoryException {
130+
if (newSizeInBytes < 0) {
131+
throw new IllegalArgumentException(
132+
String.format("Load: Invalid memory size %d bytes, must be non-negative", newSizeInBytes));
133+
}
123134
if (memoryBlock.getTotalMemorySizeInBytes() == newSizeInBytes) {
124135
return;
125136
}

0 commit comments

Comments
 (0)