apache/shardingsphere · error · FirebirdProtocolException

Truncated batch BLOB segment length

Error message

Truncated batch BLOB segment length

What it means

Thrown while parsing a Firebird 'batch blob segments' command packet: the remaining buffer holds at least one byte (so the read loop continues) but fewer than the 2 bytes needed for a segment's unsigned-short length prefix. It means the client sent a malformed or truncated batch of BLOB segments. The library throws FirebirdProtocolException because it cannot safely continue deserializing the segment list.

Source

Thrown at database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/blob/FirebirdBatchBlobSegmentsCommandPacket.java:54

    
    private final int blobHandle;
    
    private final int segmentLength;
    
    private final Collection<byte[]> segments;
    
    public FirebirdBatchBlobSegmentsCommandPacket(final FirebirdPacketPayload payload) {
        payload.skipReserved(4);
        blobHandle = payload.readBlobHandle();
        segmentLength = payload.readInt4();
        segments = readSegments(payload.readBuffer());
    }
    
    private Collection<byte[]> readSegments(final ByteBuf buffer) {
        Collection<byte[]> result = new LinkedList<>();
        while (buffer.isReadable()) {
            if (buffer.readableBytes() < Short.BYTES) {
                throw new FirebirdProtocolException("Truncated batch BLOB segment length");
            }
            int segmentLength = buffer.readUnsignedShortLE();
            if (buffer.readableBytes() < segmentLength) {
                throw new FirebirdProtocolException("Batch BLOB segment declares %d bytes, but only %d bytes remain", segmentLength, buffer.readableBytes());
            }
            byte[] segmentData = new byte[segmentLength];
            buffer.readBytes(segmentData);
            result.add(segmentData);
        }
        return result;
    }
    
    @Override
    protected void write(final FirebirdPacketPayload payload) {
    }
    
    /**
     * Get length of packet.

View on GitHub (pinned to e952770a21)

Solutions

  1. Verify the raw bytes sent by the client against the Firebird wire protocol for batch blob segment upload; every segment must be a 2-byte LE length plus that many data bytes
  2. Check for packet truncation between client and proxy (MTU/proxy framing bugs) and capture the frame with tcpdump/Wireshark
  3. If implementing a Firebird client, ensure the final segment is fully written and no stray padding byte is appended
  4. Report a bug to ShardingSphere if a stock Firebird driver reliably triggers this
Defensive patterns

Strategy: try-catch

Try / catch

try {
    new FirebirdBatchBlobSegmentsCommandPacket(payload);
} catch (FirebirdProtocolException ex) {
    // log payload.readableBytes() and the raw remaining buffer, then close the connection:
    // a truncated batch cannot be resumed safely
    throw new ProtocolViolationException("malformed batch blob segment list", ex);
}

Prevention

When it happens

Trigger: Constructing FirebirdBatchBlobSegmentsCommandPacket(FirebirdPacketPayload) where the buffered batch payload has a dangling 1-byte remainder after the last segment, or a client/proxy clipped the packet mid-length-prefix.

Common situations: Hand-written or buggy Firebird client, packet truncation by an intermediate proxy, or a protocol-version mismatch that changes the batch segment layout.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/c980b721622440d5. Report an issue: GitHub.