apache/cassandra · error · MarshalException

Not enough bytes to read a

Error message

Not enough bytes to read a %s

What it means

The FixedLengthSerializer's validate path computes expectedSize = elementSize * dimension and throws this MarshalException if the input buffer is smaller than that. Fixed-length vector values must carry exactly the full sized payload.

Solutions

  1. Ensure input has at least elementSize * dimension bytes before calling validate
  2. Reconcile the column's dimension with the actual data (ALTER to correct dimension or rewrite data)
  3. Scrub or restore SSTables if the truncation comes from storage

Example fix

// before
vectorType.validate(byteBuffer); // 8 bytes for vector<int, 4>
// after
if (byteBuffer.remaining() < 4 * 4) throw new IllegalArgumentException("vector<int,4> needs 16 bytes");
vectorType.validate(byteBuffer);
Defensive patterns

Strategy: validation

Validate before calling

int expected = elementSize * dimension;
if (input == null || accessor.size(input) < expected) throw new IllegalArgumentException("vector payload too short");

Try / catch

try { vectorType.validate(input); } catch (MarshalException e) { log.error("invalid vector value: {}", e.getMessage()); throw new IllegalArgumentException(e); }

Prevention

When it happens

Trigger: Validating a vector<fixed_length_type, N> value whose ByteBuffer is shorter than N * elementSize; passing an empty buffer; dimension in the type is larger than the data written.

Common situations: Driver/application sending truncated vectors; schema dimension changed after data was written; tests with undersized buffers; corrupted on-disk data.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/0d4770b54f6af317. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/db/marshal/VectorType.java:548

                result.add(elementSerializer.deserialize(bb, accessor));
            }
            checkConsumedFully(input, accessor, offset);

            return result;
        }

        @Override
        public <V> void validate(V input, ValueAccessor<V> accessor) throws MarshalException
        {
            if (accessor.isEmpty(input))
                rejectNullOrEmptyValue();

            int offset = 0;
            int elementSize = elementType.valueLengthIfFixed();

            int expectedSize = elementSize * dimension;
            if (accessor.size(input) < expectedSize)
                throw new MarshalException("Not enough bytes to read a " + asCQL3Type());

            for (int i = 0; i < dimension; i++)
            {
                V bb = accessor.slice(input, offset, elementSize);
                offset += elementSize;
                elementSerializer.validate(bb, accessor);
            }
            checkConsumedFully(input, accessor, offset);
        }
    }

    private class VariableLengthSerializer extends VectorSerializer
    {
        private VariableLengthSerializer()
        {
        }

        @Override

View on GitHub (pinned to 88fd0f6a0e)