{"record":{"id":"011cd5507b6b6b24","repo":"apache/cassandra","slug":"not-enough-bytes-to-read-a-vector-s-d","errorCode":null,"errorMessage":"Not enough bytes to read a vector<%s, %d>","messagePattern":"Not enough bytes to read a vector<(.+?), (.+?)>","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/db/marshal/VectorType.java","lineNumber":474,"sourceCode":"                    return rc;\n\n                offset += elementLength;\n            }\n            return 0;\n        }\n\n        @Override\n        public <V> List<V> unpack(V buffer, ValueAccessor<V> accessor)\n        {\n            if (isNull(buffer, accessor))\n                return null;\n            List<V> result = new ArrayList<>(dimension);\n            int offset = 0;\n            int elementLength = elementType.valueLengthIfFixed();\n            for (int i = 0; i < dimension; i++)\n            {\n                if (accessor.sizeFromOffset(buffer, offset) < elementLength)\n                    throw new MarshalException(String.format(\"Not enough bytes to read a vector<%s, %d>\", elementType.asCQL3Type(), dimension));\n\n                V bb = accessor.slice(buffer, offset, elementLength);\n                offset += elementLength;\n                elementSerializer.validate(bb, accessor);\n                result.add(bb);\n            }\n            checkConsumedFully(buffer, accessor, offset);\n\n            return result;\n        }\n\n        @Override\n        public <V> V pack(List<V> value, ValueAccessor<V> accessor)\n        {\n            if (value == null)\n                rejectNullOrEmptyValue();\n\n            check(value);","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/marshal/VectorType.java#L456-L492","documentation":"VectorType's unpack reads 'dimension' fixed-length elements from the buffer; if fewer bytes remain than one element's fixed length for any element, it throws this MarshalException. The serialized form of a fixed-length vector must contain exactly dimension elements of elementSize bytes each.","triggerScenarios":"unpack called on a buffer shorter than dimension * elementLength (elementLength > 0, i.e. fixed-length element types like int/float); truncated values from storage or network; dimension increased in schema while old data remains short.","commonSituations":"Truncated SSTable/commit-log data; schema dimension mismatch after ALTER of vector dimension; hand-crafted buffers in tests; partial reads from a custom transport.","solutions":["Verify the input buffer size equals or exceeds dimension * elementType.valueLengthIfFixed() before unpacking","Confirm the vector column dimension matches the data as written (did not change since write)","Scrub/repair affected SSTables if storage data is truncated; restore from backup if corruption is confirmed"],"exampleFix":"// before\nif (buffer.remaining() < dimension * elementSize) throw new IllegalArgumentException(\"truncated vector\");\nvectorType.unpack(buffer);\n// after\nint elementSize = elementType.valueLengthIfFixed();\nif (buffer.remaining() < dimension * elementSize) throw new IllegalArgumentException(\"truncated vector\");\nvectorType.unpack(buffer);","handlingStrategy":"validation","validationCode":"if (buffer.remaining() < dimension * elementType.valueLengthIfFixed()) throw new IllegalArgumentException(\"truncated vector payload\");","typeGuard":null,"tryCatchPattern":"try { vectorType.unpack(buffer); } catch (MarshalException e) { log.error(\"cannot unpack vector: {}\", e.getMessage()); return null; }","preventionTips":["Validate payload length before deserialization","Keep schema dimension stable; migrate data when it changes","Scrub/repair storage if truncation is observed repeatedly"],"tags":["cassandra","serialization","truncated-data","vector-type"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}