{"record":{"id":"7aec0400424e42dd","repo":"apache/flink","slug":"byte-array-does-not-provide-enough-space-to-store","errorCode":null,"errorMessage":"Byte array does not provide enough space to store requested data.","messagePattern":"Byte array does not provide enough space to store requested data\\.","errorType":"exception","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java","lineNumber":393,"sourceCode":"\n        if (skippedBytes < numBytes) {\n            throw new EOFException(\"Could not skip \" + numBytes + \" bytes.\");\n        }\n    }\n\n    @Override\n    public int read(@Nonnull byte[] b, int off, int len) throws IOException {\n\n        if (off < 0) {\n            throw new IndexOutOfBoundsException(\"Offset cannot be negative.\");\n        }\n\n        if (len < 0) {\n            throw new IndexOutOfBoundsException(\"Length cannot be negative.\");\n        }\n\n        if (b.length - off < len) {\n            throw new IndexOutOfBoundsException(\n                    \"Byte array does not provide enough space to store requested data\" + \".\");\n        }\n\n        if (this.position >= this.end) {\n            return len == 0 ? 0 : -1;\n        } else {\n            int toRead = Math.min(this.end - this.position, len);\n            System.arraycopy(this.buffer, this.position, b, off, toRead);\n            this.position += toRead;\n\n            return toRead;\n        }\n    }\n\n    @Override\n    public int read(@Nonnull byte[] b) throws IOException {\n        return read(b, 0, b.length);\n    }","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/memory/DataInputDeserializer.java#L375-L411","documentation":"Thrown by DataInputDeserializer.read(byte[], int off, int len) when the destination array cannot hold the requested bytes: b.length - off < len. The destination is too small for the read.","triggerScenarios":"Calling read(b, off, len) where b.length - off < len (e.g. reading 16 bytes into an 8-byte array, or with a large offset that leaves insufficient room).","commonSituations":"Destination buffer sized too small for the record; an offset that eats into available space; mis-sizing a read buffer relative to the declared record length.","solutions":["Size the destination array to at least off + len before calling read.","Use read(byte[]) with a correctly sized array.","Derive the destination length from the record's declared size, not a fixed constant."],"exampleFix":"// before\nbyte[] dst = new byte[8];\ninput.read(dst, 0, recordLen); // recordLen > 8\n\n// after\nbyte[] dst = new byte[recordLen];\ninput.read(dst, 0, recordLen);","handlingStrategy":"validation","validationCode":"if (off < 0 || len < 0 || b.length - off < len) {\n    throw new IndexOutOfBoundsException(\"dst too small: len=\" + len + \", off=\" + off + \", cap=\" + b.length);\n}\ninput.read(b, off, len);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size the destination array to at least off + len.","Derive destination length from the record's declared size, not a fixed constant.","Use read(byte[]) with a correctly sized array when reading the full payload."],"tags":["serialization","bounds-check","deserialization","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}