{"record":{"id":"17389eb20ba08be4","repo":"nautechsystems/nautilus_trader","slug":"buffer-too-short-for-field-length-expected","errorCode":null,"errorMessage":"Buffer too short for {field} length: expected {}, was {}","messagePattern":"Buffer too short for (.+?) length: expected (.+?), was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs","lineNumber":108,"sourceCode":"    let min_block_len = execution_report_min_block_length(version);\n    if usize::from(block_length) < min_block_len {\n        anyhow::bail!(\n            \"SBE execution report block length too short: expected at least {min_block_len}, was {block_length}\"\n        );\n    }\n\n    let min_len = HEADER_LEN + usize::from(block_length);\n    if data.len() < min_len {\n        anyhow::bail!(\n            \"Buffer too short for fixed block: expected {min_len}, was {}\",\n            data.len()\n        );\n    }\n\n    let mut field_offset = min_len;\n    for field in EXECUTION_REPORT_VAR_DATA_FIELDS {\n        let Some(length) = data.get(field_offset) else {\n            anyhow::bail!(\n                \"Buffer too short for {field} length: expected {}, was {}\",\n                field_offset + 1,\n                data.len()\n            );\n        };\n        let expected_len = field_offset + 1 + usize::from(*length);\n        if data.len() < expected_len {\n            anyhow::bail!(\n                \"Buffer too short for {field}: expected {expected_len}, was {}\",\n                data.len()\n            );\n        }\n        field_offset = expected_len;\n    }\n\n    let mut dec = execution_report_event_codec::ExecutionReportEventDecoder::default().wrap(\n        buf,\n        HEADER_LEN,","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the full frame including all six length-prefixed variable fields","Fix the slicing offset so the buffer extends past the fixed block","Re-capture or re-encode truncated fixtures with the codec","Add a length check on the raw message before invoking the decoder"],"exampleFix":"// before\nlet report = decode_execution_report(&frame[..min_len])?; // dropped var-length section\n// after\nlet report = decode_execution_report(&frame)?; // include full frame","handlingStrategy":"validation","validationCode":"pub fn var_length_section_present(data: &[u8]) -> bool {\n    if data.len() < 8 { return false; }\n    let block_length = u16::from_be_bytes([data[0], data[1]]) as usize;\n    data.len() > 8 + block_length // at least the first length byte exists\n}","typeGuard":null,"tryCatchPattern":"match decode_execution_report(&frame) {\n    Ok(r) => handle(r),\n    Err(e) if e.to_string().contains(\"length\") && e.to_string().contains(\"Buffer too short\") => {\n        request_retransmit_or_drop(&frame);\n    }\n    Err(e) => log::warn!(\"SBE decode failed: {e}\"),\n}","preventionTips":["Treat frames as atomic messages; never decode partial buffers","Validate total frame length against fixed block + var-length field sizes","Re-capture fixtures whenever a codec changes the var-field layout","Log the full hex of failed frames for post-mortem"],"tags":["sbe","binance","buffer","truncated"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}