{"record":{"id":"ba48829f37677e26","repo":"alibaba/nacos","slug":"input-array-too-big-the-output-array-would-be-big","errorCode":null,"errorMessage":"Input array too big, the output array would be bigger ({len}) than the specified maximum size of {maxResultSize}","messagePattern":"Input array too big, the output array would be bigger \\((.+?)\\) than the specified maximum size of (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"common/src/main/java/com/alibaba/nacos/common/codec/Base64.java","lineNumber":408,"sourceCode":"     *                      characters.\n     * @param maxResultSize The maximum result size to accept.\n     * @return Base64-encoded data.\n     * @throws IllegalArgumentException Thrown when the input array needs an output array bigger than maxResultSize\n     * @since 1.4\n     */\n    public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe,\n        int maxResultSize) {\n        if (binaryData == null || binaryData.length == 0) {\n            return binaryData;\n        }\n        \n        // Create this so can use the super-class method\n        // Also ensures that the same roundings are performed by the ctor and the code\n        Base64 b64 = isChunked ? new Base64(MIME_CHUNK_SIZE, CHUNK_SEPARATOR, urlSafe)\n            : new Base64(0, CHUNK_SEPARATOR, urlSafe);\n        long len = b64.getEncodedLength(binaryData);\n        if (len > maxResultSize) {\n            throw new IllegalArgumentException(\n                \"Input array too big, the output array would be bigger (\" + len\n                    + \") than the specified maximum size of \" + maxResultSize);\n        }\n        \n        return b64.encode(binaryData);\n    }\n    \n    /**\n     * Decodes Base64 data into octets.\n     *\n     * @param base64Data Byte array containing Base64 data\n     * @return Array containing decoded data.\n     */\n    public static byte[] decodeBase64(byte[] base64Data) {\n        return new Base64().decode(base64Data);\n    }\n    \n    /**","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/codec/Base64.java#L390-L426","documentation":"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.","triggerScenarios":"Calling encodeBase64(largeArray, isChunked, urlSafe, maxResultSize) where largeArray.length * 4/3 > maxResultSize. The caller explicitly set a ceiling that the input would breach.","commonSituations":"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.","solutions":["Increase maxResultSize to accommodate the expected encoded output (approximately 4/3 of the input size, plus chunking overhead if isChunked is true).","If the input is unexpectedly large, investigate the data source to ensure it is not corrupted or excessively large.","Consider streaming the encoding instead of buffering the entire output if memory is constrained."],"exampleFix":"// before\nbyte[] encoded = Base64.encodeBase64(data, false, false, 1024);\n\n// after — size limit proportional to input\nint max = (int) (data.length * 1.4 + 16);\nbyte[] encoded = Base64.encodeBase64(data, false, false, max);","handlingStrategy":"validation","validationCode":"long encodedLen = (long) Math.ceil(binaryData.length * 4.0 / 3.0);\nif (encodedLen > maxResultSize) {\n    throw new IllegalArgumentException(\"Input too large for maxResultSize: encoded length \"\n        + encodedLen + \" exceeds \" + maxResultSize);\n}","typeGuard":null,"tryCatchPattern":"try {\n    encoded = Base64.encodeBase64(data, chunked, urlSafe, maxResultSize);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"too big\")) {\n        // Increase the limit or split the input into chunks\n        maxResultSize = (int) (data.length * 1.4 + 16);\n        encoded = Base64.encodeBase64(data, chunked, urlSafe, maxResultSize);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Calculate maxResultSize as approximately 4/3 of the expected input size.","Add chunking overhead if isChunked is true.","Validate input size before calling encodeBase64 when a ceiling is enforced."],"tags":["base64","encoding","validation","size-limit"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}