{"record":{"id":"b6c7a96fc485636b","repo":"nautechsystems/nautilus_trader","slug":"buffer-too-short-for-sbe-header-expected-header","errorCode":null,"errorMessage":"Buffer too short for SBE header: expected {HEADER_LEN}, was {}","messagePattern":"Buffer too short for SBE header: expected (.+?), was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs","lineNumber":64,"sourceCode":"    \"symbol\",\n    \"client_order_id\",\n    \"orig_client_order_id\",\n    \"commission_asset\",\n    \"reject_reason\",\n    \"counter_symbol\",\n];\n\n/// Decodes an SBE ExecutionReportEvent (template 603) into a [`BinanceSpotExecutionReport`].\n///\n/// The input buffer must include the 8-byte SBE message header.\n///\n/// # Errors\n///\n/// Returns error if the buffer is too short, the template ID is wrong,\n/// the schema ID does not match, or variable-length data is malformed.\npub fn decode_execution_report(data: &[u8]) -> anyhow::Result<BinanceSpotExecutionReport> {\n    if data.len() < HEADER_LEN {\n        anyhow::bail!(\n            \"Buffer too short for SBE header: expected {HEADER_LEN}, was {}\",\n            data.len()\n        );\n    }\n\n    let buf = ReadBuf::new(data);\n    let block_length = buf.get_u16_at(0);\n    let template_id = buf.get_u16_at(2);\n    let schema_id = buf.get_u16_at(4);\n    let version = buf.get_u16_at(6);\n\n    if template_id != execution_report_event_codec::SBE_TEMPLATE_ID {\n        anyhow::bail!(\n            \"Wrong template ID: expected {}, received {template_id}\",\n            execution_report_event_codec::SBE_TEMPLATE_ID\n        );\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs#L46-L82","documentation":"decode_execution_report parses a binary SBE-encoded Binance Spot execution report. SBE frames begin with a fixed-size header (block length, template ID, schema ID, version); if the input buffer is shorter than HEADER_LEN it cannot even be interpreted as a header, so decoding bails immediately.","triggerScenarios":"decode_execution_report receiving a payload shorter than HEADER_LEN bytes — a truncated WS frame, a text (non-SBE) message passed to the SBE decoder, or an off-by-slice error cutting the message before the full header arrives.","commonSituations":"Accidentally feeding JSON stream payloads into the SBE trading decoder; network fragmentation/truncation bugs in message reassembly; test fixtures that are intentionally truncated (e.g. test_decode_execution_report_truncated_header) or wrongly built.","solutions":["Check data.len() in the message against HEADER_LEN to see how short the buffer is — a tiny length (e.g. <10 bytes) usually means the wrong payload type was passed.","Verify the WS message routing: only trading (SBE) binary frames should reach this decoder, not public JSON text frames.","Fix frame reassembly so complete messages are delivered to the decoder before invocation.","If intentional truncation handling is needed, validate data.len() >= HEADER_LEN at the call site first."],"exampleFix":"// before\ndecode_execution_report(&payload)?;\n// after\nif payload.len() >= HEADER_LEN {\n    decode_execution_report(&payload)?;\n} else {\n    log::warn!(\"skipping short frame: {} bytes\", payload.len());\n}","handlingStrategy":"validation","validationCode":"fn is_decodable_sbe_frame(data: &[u8]) -> bool { data.len() >= HEADER_LEN }","typeGuard":null,"tryCatchPattern":"if data.len() < HEADER_LEN {\n    log::warn!(\"short frame ({} bytes), skipping\", data.len());\n    return Ok(None);\n}\nlet report = decode_execution_report(data)?;","preventionTips":["Route only binary trading-stream frames to the SBE decoder; keep JSON public-stream frames on the JSON parser.","Reassemble complete WS frames before handing payloads to the decoder.","Check buffer length against HEADER_LEN at the call site before decoding.","Validate test fixtures build full SBE messages, not truncated ones."],"tags":["sbe","decoding","binance","spot","websocket","truncated-message"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}