{"record":{"id":"a8605193bd7ee486","repo":"rtk-ai/rtk","slug":"negative-event-length","errorCode":null,"errorMessage":"negative event length: {}","messagePattern":"negative event length: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cmds/dotnet/binlog.rs","lineNumber":364,"sourceCode":"                parsed.string_records.push(text);\n            }\n            RECORD_NAME_VALUE_LIST | RECORD_PROJECT_IMPORT_ARCHIVE => {\n                let len = reader\n                    .read_7bit_i32()\n                    .context(\"failed to read record length\")?;\n                if len < 0 {\n                    anyhow::bail!(\"negative record length: {}\", len);\n                }\n                reader\n                    .skip(len as usize)\n                    .context(\"failed to skip auxiliary record payload\")?;\n            }\n            _ => {\n                let len = reader\n                    .read_7bit_i32()\n                    .context(\"failed to read event length\")?;\n                if len < 0 {\n                    anyhow::bail!(\"negative event length: {}\", len);\n                }\n\n                let payload = reader\n                    .read_exact(len as usize)\n                    .context(\"failed to read event payload\")?;\n                let mut event_reader = BinReader::new(payload);\n                let _ =\n                    parse_event_record(kind, &mut event_reader, file_format_version, &mut parsed);\n            }\n        }\n    }\n\n    Ok(parsed)\n}\n\nfn parse_event_record(\n    kind: i32,\n    reader: &mut BinReader<'_>,","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/dotnet/binlog.rs#L346-L382","documentation":"For any record type not specifically handled, the parser reads a 7-bit-encoded signed event length; a negative value means the byte stream is corrupt or the parser has lost synchronization with the record boundaries. Since a length-prefixed payload cannot have negative size, the parser bails before calling read_exact, which would otherwise receive a negative-cast usize.","triggerScenarios":"The _ catch-all arm of the record loop in parse_events_from_binlog decodes read_7bit_i32() and gets len < 0 — caused by offset drift after an unknown/misparsed record type, truncation mid-record, or decoding arbitrary bytes as a binlog.","commonSituations":"A build killed mid-write leaving a truncated tail record; a binlog from a newer/older MSBuild whose record layout differs and desynchronizes the parser; pointing the tool at a random gzip file renamed to .binlog.","solutions":["Regenerate the binlog: re-run `dotnet build -bl:build.binlog` with a current SDK.","Verify file integrity — compare size/checksum against the CI artifact; a truncated file explains mid-record corruption.","Ensure the input path really is a binlog and was produced by MSBuild (check gzip header and version >= 18).","If it happens on intact logs, audit the record-type switch so unknown records keep the stream aligned."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure the file is complete: no concurrent writer, gzip stream ends cleanly\nlet mut d = flate2::read::GzDecoder::new(std::fs::File::open(path)?);\nlet mut payload = Vec::new();\nd.read_to_end(&mut payload)?;\nif !d.header().map(|h| h.extra().is_some()).unwrap_or(true) || d.status().is_err() {\n    bail!(\"binlog gzip stream is truncated\");\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = parse_result {\n    if e.to_string().contains(\"negative event length\") {\n        eprintln!(\"binlog stream corrupted or truncated; re-run dotnet build -bl\");\n        return regenerate_binlog();\n    }\n    return Err(e);\n}","preventionTips":["Wait for the build process to fully exit before consuming its binlog","Detect truncation: gzip decode errors or sizes far below expected indicate partial writes","Run binlog-producing builds on storage with sufficient free space","Avoid pointing the tool at arbitrary .gz files; only parse MSBuild-produced -bl output"],"tags":["dotnet","binlog","corrupt-file","parsing"],"backgroundTag":"value-out-of-range","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}