nautechsystems/nautilus_trader · error

Buffer too short for {field} length: expected {}, was {}

Error message

Buffer too short for {field} length: expected {}, was {}

What it means

After the fixed block, the ExecutionReportEvent carries six variable-length fields, each prefixed by a 1-byte length. This error fires when the buffer ends before the length byte of one of these fields (symbol, client_order_id, orig_client_order_id, commission_asset, reject_reason, counter_symbol) can be read.

Source

Thrown at crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs:108

    let min_block_len = execution_report_min_block_length(version);
    if usize::from(block_length) < min_block_len {
        anyhow::bail!(
            "SBE execution report block length too short: expected at least {min_block_len}, was {block_length}"
        );
    }

    let min_len = HEADER_LEN + usize::from(block_length);
    if data.len() < min_len {
        anyhow::bail!(
            "Buffer too short for fixed block: expected {min_len}, was {}",
            data.len()
        );
    }

    let mut field_offset = min_len;
    for field in EXECUTION_REPORT_VAR_DATA_FIELDS {
        let Some(length) = data.get(field_offset) else {
            anyhow::bail!(
                "Buffer too short for {field} length: expected {}, was {}",
                field_offset + 1,
                data.len()
            );
        };
        let expected_len = field_offset + 1 + usize::from(*length);
        if data.len() < expected_len {
            anyhow::bail!(
                "Buffer too short for {field}: expected {expected_len}, was {}",
                data.len()
            );
        }
        field_offset = expected_len;
    }

    let mut dec = execution_report_event_codec::ExecutionReportEventDecoder::default().wrap(
        buf,
        HEADER_LEN,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass the full frame including all six length-prefixed variable fields
  2. Fix the slicing offset so the buffer extends past the fixed block
  3. Re-capture or re-encode truncated fixtures with the codec
  4. Add a length check on the raw message before invoking the decoder

Example fix

// before
let report = decode_execution_report(&frame[..min_len])?; // dropped var-length section
// after
let report = decode_execution_report(&frame)?; // include full frame
Defensive patterns

Strategy: validation

Validate before calling

pub fn var_length_section_present(data: &[u8]) -> bool {
    if data.len() < 8 { return false; }
    let block_length = u16::from_be_bytes([data[0], data[1]]) as usize;
    data.len() > 8 + block_length // at least the first length byte exists
}

Try / catch

match decode_execution_report(&frame) {
    Ok(r) => handle(r),
    Err(e) if e.to_string().contains("length") && e.to_string().contains("Buffer too short") => {
        request_retransmit_or_drop(&frame);
    }
    Err(e) => log::warn!("SBE decode failed: {e}"),
}

Prevention

When it happens

Trigger: Calling decode_execution_report with a buffer that covers the 8-byte header and fixed block but stops at or before the start of a variable-length field's length byte — e.g. truncation, an off-by-one slice, or a fixture whose declared var-field data was cut off.

Common situations: Frame truncation during capture or network reassembly; slicing the payload with an end index equal to the fixed-block end; fixtures generated without the trailing var-length section.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/17389eb20ba08be4. Report an issue: GitHub.