alibaba/nacos · warning · IllegalArgumentException

Input array too big, the output array would be bigger ({len}

Error message

Input array too big, the output array would be bigger ({len}) than the specified maximum size of {maxResultSize}

What it means

Thrown by Base64.encodeBase64() as an IllegalArgumentException when the computed encoded output length exceeds the caller-specified maxResultSize limit. The method calculates the expected encoded length via getEncodedLength() and compares it to maxResultSize before performing the actual encoding. This is a safety guard against excessive memory allocation from large inputs. Null or empty input arrays pass through without error.

Source

Thrown at common/src/main/java/com/alibaba/nacos/common/codec/Base64.java:408

     *                      characters.
     * @param maxResultSize The maximum result size to accept.
     * @return Base64-encoded data.
     * @throws IllegalArgumentException Thrown when the input array needs an output array bigger than maxResultSize
     * @since 1.4
     */
    public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe,
        int maxResultSize) {
        if (binaryData == null || binaryData.length == 0) {
            return binaryData;
        }
        
        // Create this so can use the super-class method
        // Also ensures that the same roundings are performed by the ctor and the code
        Base64 b64 = isChunked ? new Base64(MIME_CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe)
            : new Base64(0, CHUNK_SEPARATOR, urlSafe);
        long len = b64.getEncodedLength(binaryData);
        if (len > maxResultSize) {
            throw new IllegalArgumentException(
                "Input array too big, the output array would be bigger (" + len
                    + ") than the specified maximum size of " + maxResultSize);
        }
        
        return b64.encode(binaryData);
    }
    
    /**
     * Decodes Base64 data into octets.
     *
     * @param base64Data Byte array containing Base64 data
     * @return Array containing decoded data.
     */
    public static byte[] decodeBase64(byte[] base64Data) {
        return new Base64().decode(base64Data);
    }
    
    /**

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Increase maxResultSize to accommodate the expected encoded output (approximately 4/3 of the input size, plus chunking overhead if isChunked is true).
  2. If the input is unexpectedly large, investigate the data source to ensure it is not corrupted or excessively large.
  3. Consider streaming the encoding instead of buffering the entire output if memory is constrained.

Example fix

// before
byte[] encoded = Base64.encodeBase64(data, false, false, 1024);

// after — size limit proportional to input
int max = (int) (data.length * 1.4 + 16);
byte[] encoded = Base64.encodeBase64(data, false, false, max);
Defensive patterns

Strategy: validation

Validate before calling

long encodedLen = (long) Math.ceil(binaryData.length * 4.0 / 3.0);
if (encodedLen > maxResultSize) {
    throw new IllegalArgumentException("Input too large for maxResultSize: encoded length "
        + encodedLen + " exceeds " + maxResultSize);
}

Try / catch

try {
    encoded = Base64.encodeBase64(data, chunked, urlSafe, maxResultSize);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("too big")) {
        // Increase the limit or split the input into chunks
        maxResultSize = (int) (data.length * 1.4 + 16);
        encoded = Base64.encodeBase64(data, chunked, urlSafe, maxResultSize);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling encodeBase64(largeArray, isChunked, urlSafe, maxResultSize) where largeArray.length * 4/3 > maxResultSize. The caller explicitly set a ceiling that the input would breach.

Common situations: Processing large config payloads or binary blobs through Base64 with a restrictive maxResultSize; misconfigured size limits; denial-of-service protection triggering on legitimate large payloads.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/ba48829f37677e26. Report an issue: GitHub.