{"record":{"id":"395456b51b798bbb","repo":"nautechsystems/nautilus_trader","slug":"buffer-too-short-for-fixed-block-expected-min-le","errorCode":null,"errorMessage":"Buffer too short for fixed block: expected {min_len}, was {}","messagePattern":"Buffer too short for fixed block: expected (.+?), was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs","lineNumber":99,"sourceCode":"    }\n\n    if schema_id != crate::spot::sbe::spot::SBE_SCHEMA_ID {\n        anyhow::bail!(\n            \"Wrong schema ID: expected {}, received {schema_id}\",\n            crate::spot::sbe::spot::SBE_SCHEMA_ID\n        );\n    }\n\n    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 {}\",","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/websocket/trading/decode_sbe.rs#L81-L117","documentation":"After validating the header, the decoder requires HEADER_LEN + block_length bytes (8-byte header plus the fixed field block). This error means the buffer ends before the fixed block completes, so fixed-width fields would run past the end of the data. The decoder bails instead of performing an out-of-bounds read.","triggerScenarios":"Calling decode_execution_report with a slice shorter than 8 + block_length bytes — e.g. a WebSocket message split across frames and naively concatenated, a partially written capture file, or slicing a buffer with the wrong offset/length.","commonSituations":"Incorrect frame framing/reassembly in the WebSocket layer; reading binary logs with a wrong record boundary; tests passing only the body without the 8-byte SBE header.","solutions":["Ensure the complete SBE frame (header + full fixed block + var-length fields) is passed to the decoder","Fix stream reassembly so fragmented WebSocket messages are joined before decoding","Include the 8-byte SBE message header when slicing the payload","Re-capture or regenerate truncated test fixtures"],"exampleFix":"// before\nlet report = decode_execution_report(&payload[8..])?; // header stripped twice\n// after\nlet report = decode_execution_report(&payload)?; // decoder expects header included","handlingStrategy":"validation","validationCode":"pub fn frame_complete(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\n}","typeGuard":"fn complete_frame<'a>(data: &'a [u8]) -> Option<&'a [u8]> {\n    (data.len() >= 8 && {\n        let bl = u16::from_be_bytes([data[0], data[1]]) as usize;\n        data.len() >= 8 + bl\n    }).then_some(data)\n}","tryCatchPattern":"match decode_execution_report(&frame) {\n    Ok(r) => handle(r),\n    Err(e) if e.to_string().contains(\"Buffer too short\") => buffer_for_reassembly(&frame),\n    Err(e) => log::warn!(\"SBE decode failed: {e}\"),\n}","preventionTips":["Reassemble fragmented WebSocket messages fully before decoding","Never strip the 8-byte SBE header before passing the payload","Use length-prefixed framing when persisting/replaying binary captures","Add unit tests asserting fixtures include header + full block"],"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-14T05:17:10.506Z"}