{"record":{"id":"fdca7083044cf612","repo":"apache/cassandra","slug":"not-enough-bytes-to-read-a-name","errorCode":null,"errorMessage":"Not enough bytes to read a + name","messagePattern":"Not enough bytes to read a \\+ name","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/AbstractMapSerializer.java","lineNumber":112,"sourceCode":"                }\n\n                // Otherwise, we'll include that element\n                skipMapValue(input); // value\n                ++count;\n\n                // But if we know it was the last of the slice, we break early\n                if (comparison == 0)\n                    break;\n            }\n\n            if (count == 0 && !frozen)\n                return null;\n\n            return copyAsNewCollection(collection, count, startPos, input.position());\n        }\n        catch (BufferUnderflowException | IndexOutOfBoundsException e)\n        {\n            throw new MarshalException(\"Not enough bytes to read a \" + name);\n        }\n    }\n\n    @Override\n    public int getIndexFromSerialized(ByteBuffer collection, ByteBuffer key, AbstractType<?> comparator)\n    {\n        try\n        {\n            ByteBuffer input = collection.duplicate();\n            int n = readCollectionSize(input, ByteBufferAccessor.instance);\n            int offset = sizeOfCollectionSize();\n            for (int i = 0; i < n; i++)\n            {\n                ByteBuffer kbb = readValue(input, ByteBufferAccessor.instance, offset);\n                offset += sizeOfValue(kbb, ByteBufferAccessor.instance);\n                int comparison = comparator.compareForCQL(kbb, key);\n\n                if (comparison == 0)","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/AbstractMapSerializer.java#L94-L130","documentation":"AbstractMapSerializer.getSliceFromSerialized converts the catch-all BufferUnderflowException/IndexOutOfBoundsException raised while walking a serialized map/set into MarshalException(\"Not enough bytes to read a map\"). It means the supplied serialized collection buffer is truncated or corrupt relative to its declared element count.","triggerScenarios":"Calling getSliceFromSerialized (used for frozen collection slicing in CQL) with a ByteBuffer shorter than the header/element count claims — e.g. a corrupted stored value, wrong comparator usage, or hand-built byte buffers missing elements (src/java/org/apache/cassandra/serializers/AbstractMapSerializer.java:112).","commonSituations":"Corrupted SSTable or hinted data; client drivers writing malformed frozen map values; custom tooling reading cells with truncated buffers; deserializing a value with the wrong type.","solutions":["Verify the value was written with the correct collection type; a map read as a set (or vice versa) yields truncated parsing.","Re-read/repair the affected data (nodetool scrub/repair) if the stored value is corrupt on disk.","In client code, ensure the serialized buffer is complete before calling collection slicing APIs.","Catch MarshalException around deserialization and treat the value as unreadable, logging the hex of the input."],"exampleFix":"// before\nList<ByteBuffer> slices = type.getSliceFromSerialized(value, start, end); // MarshalException\n// after\ntry {\n    slices = type.getSliceFromSerialized(value, start, end);\n} catch (MarshalException e) {\n    logger.warn(\"Corrupt collection value: {}\", ByteBufferUtil.bytesToHex(value));\n}","handlingStrategy":"try-catch","validationCode":"if (value == null || value.remaining() < 4) throw new MarshalException(\"collection buffer too short\");","typeGuard":null,"tryCatchPattern":"try { slices = mapType.getSliceFromSerialized(value, from, to); } catch (MarshalException e) { logger.warn(\"Truncated map cell: {}\", ByteBufferUtil.bytesToHex(value), e); }","preventionTips":["Always write collections through typed driver statements","Run nodetool repair/scrub regularly to catch corruption","Verify schema matches data when using sstableloader or migrations","Catch MarshalException whenever reading frozen collections"],"tags":["serialization","marshal","collection","corrupt-data"],"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"}