Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class ByteArrayOutputStream extends OutputStream {
*/
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

/**
* Maximum size of a single buffer (16MB) to prevent excessive memory allocation.
* When buffers need to grow beyond this size, additional buffers are created instead.
*/
private static final int MAX_BUFFER_SIZE = 16 * 1024 * 1024;

/**
* The list of buffers, which grows and never reduces.
*/
Expand Down Expand Up @@ -136,6 +142,9 @@ private void needNewBuffer(final int newcount) {
filledBufferSum += currentBuffer.length;
}

// Cap the buffer size to prevent excessive memory allocation
newBufferSize = Math.min(newBufferSize, MAX_BUFFER_SIZE);

currentBufferIndex++;
currentBuffer = new byte[newBufferSize];
buffers.add(currentBuffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ConcurrentJarCreator(int nThreads) throws IOException {
*/
public ConcurrentJarCreator(boolean compressAddedZips, int nThreads) throws IOException {
this.compressAddedZips = compressAddedZips;
ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier(100000000 / nThreads);
ScatterGatherBackingStoreSupplier defaultSupplier = new DeferredSupplier(10000000 / nThreads);
metaInfDir = createDeferred(defaultSupplier);
manifest = createDeferred(defaultSupplier);
directories = createDeferred(defaultSupplier);
Expand Down
Loading