From 377d0d131eb45d6a443175c13f1b65eb8efcd952 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 26 Nov 2021 17:30:14 +1100 Subject: [PATCH] Issue #6974 - fix bug in ByteBufferPool implementations If an allocation size of 0 was requested bucketFor would throw. Signed-off-by: Lachlan Roberts --- .../main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java | 2 +- .../main/java/org/eclipse/jetty/io/MappedByteBufferPool.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java index 806cddfac3e..4c968dd4348 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ArrayByteBufferPool.java @@ -197,7 +197,7 @@ public class ArrayByteBufferPool extends AbstractByteBufferPool implements Dumpa protected int bucketFor(int capacity) { - return (int)Math.ceil((double)capacity / getCapacityFactor()); + return Math.max((int)Math.ceil((double)capacity / getCapacityFactor()), 1); } protected int capacityFor(int bucket) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java index 85a92b9f271..99732d7c2b0 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/MappedByteBufferPool.java @@ -176,7 +176,7 @@ public class MappedByteBufferPool extends AbstractByteBufferPool implements Dump } if (index >= 0) { - Bucket bucket = buckets.get(index); + Bucket bucket = buckets.remove(index); // Null guard in case this.clear() is called concurrently. if (bucket != null) bucket.clear(); @@ -185,7 +185,7 @@ public class MappedByteBufferPool extends AbstractByteBufferPool implements Dump protected int bucketFor(int capacity) { - return (int)Math.ceil((double)capacity / getCapacityFactor()); + return Math.max((int)Math.ceil((double)capacity / getCapacityFactor()), 1); } protected int capacityFor(int bucket)