{"record":{"id":"84664f42471ddc92","repo":"oracle/graal","slug":"can-not-request-d-bytes-buffer-capacity-is-d","errorCode":null,"errorMessage":"Can not request %d bytes: buffer capacity is %d","messagePattern":"Can not request (.+?) bytes: buffer capacity is (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/BinarySource.java","lineNumber":286,"sourceCode":"            return null;\n        }\n        ensureAvailable(len * 4);\n        int[] props = new int[len];\n        for (int i = 0; i < len; i++) {\n            props[i] = buffer.getInt();\n        }\n        return props;\n    }\n\n    @Override\n    public String readString() throws IOException {\n        // readString is only called from CP reads, CP items are cached, no need to intern\n        return new String(readBytes(), StandardCharsets.UTF_8);\n    }\n\n    private void ensureAvailable(int i) throws IOException {\n        if (i > buffer.capacity()) {\n            throw new IllegalArgumentException(String.format(\"Can not request %d bytes: buffer capacity is %d\", i, buffer.capacity()));\n        }\n        while (buffer.remaining() < i) {\n            fill();\n        }\n    }\n\n    @Override\n    public boolean readHeader() throws IOException {\n        // Check for a version specification\n        byte[] magic = peekBytes(MAGIC_BYTES.length);\n        if (Arrays.equals(MAGIC_BYTES, magic)) {\n            // Consume the bytes for real\n            readBytes(MAGIC_BYTES.length);\n            setVersion(readByte(), readByte());\n            return true;\n        } else {\n            return false;\n        }","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/graphio/parsing/BinarySource.java#L268-L304","documentation":"BinarySource decodes through a fixed 256 KB direct ByteBuffer; ensureAvailable rejects any single read whose required byte count exceeds that capacity with IllegalArgumentException('Can not request N bytes: buffer capacity is M'). In practice N comes from a length prefix in the file (e.g. a string or byte-array length), so a huge value almost always means the stream is corrupt or misaligned rather than that a legitimate 256 KB+ item exists.","triggerScenarios":"A corrupted length field (e.g. reading random bytes as an int length) producing a request > 262144; stream desynchronization causing a data value to be interpreted as a length; genuinely oversized pool entries written by custom producers.","commonSituations":"Parsing damaged/truncated dumps; reading files whose earlier fields were misparsed, shifting bytes; custom writers emitting very large code blobs or strings in single pool entries.","solutions":["Regenerate the dump; treat this as corruption evidence and verify file integrity first.","If you control the writer, split oversized entries (strings/byte arrays) or confirm they stay under 256 KB.","If large entries are legitimate for your format, read via a source with a larger buffer or a streaming read path rather than relying on the fixed-capacity buffer.","Check the requested byte count in the message: values near Integer.MAX_VALUE strongly indicate misalignment, not real data."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { reader.parse(); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"buffer capacity\")) { /* corrupt length field or oversized entry: verify/re-dump */ } }","preventionTips":["Keep single pool entries (strings, code blobs) under the reader's 256 KB buffer when writing custom dumps.","Treat absurd requested lengths as evidence of stream desync, not as data to grow buffers for.","Verify file integrity before parsing to avoid misreading lengths."],"tags":["graphio","parsing","buffer-limits","corrupt-input"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}