{"record":{"id":"65faa332af893095","repo":"rtk-ai/rtk","slug":"negative-record-length","errorCode":null,"errorMessage":"negative record length: {}","messagePattern":"negative record length: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cmds/dotnet/binlog.rs","lineNumber":353,"sourceCode":"            .read_7bit_i32()\n            .context(\"failed to read record kind\")?;\n        if kind == RECORD_END_OF_FILE {\n            break;\n        }\n\n        match kind {\n            RECORD_STRING => {\n                let text = reader\n                    .read_dotnet_string()\n                    .context(\"failed to read string record\")?;\n                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 _ =","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/dotnet/binlog.rs#L335-L371","documentation":"While walking the binlog stream, records of type RECORD_NAME_VALUE_LIST or RECORD_PROJECT_IMPORT_ARCHIVE are prefixed with a 7-bit-encoded signed length. A negative length means the stream is corrupt or being misparsed — a real record cannot have negative payload size. The parser bails instead of passing a negative value to skip(), which would panic or misbehave when cast to usize.","triggerScenarios":"parse_events_from_binlog's record loop decodes read_7bit_i32() for an auxiliary record and gets len < 0, typically because the read offset has drifted (corrupt file, unsupported record variant parsed with the wrong layout) or the 7-bit encoding decodes a large value that wraps negative.","commonSituations":"Hand-edited or partially written binlog; a binlog produced by an MSBuild version emitting record types this parser misclassifies; feeding a non-binlog gzip file (or random bytes) into the parser.","solutions":["Regenerate the binlog with a current .NET SDK — the file is almost certainly corrupt or truncated.","Confirm the input is actually a binlog (gzip magic + version header >= 18) and not an arbitrary gzip/text file.","Retry the producing build; if it was interrupted (disk full, process killed), a partial stream explains the corruption.","If it recurs on valid files, extend the parser's record-type handling so offsets stay aligned with the actual stream layout."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// sanity check: file should be valid gzip and non-trivially large\nlet bytes = std::fs::read(path)?;\nif bytes.len() < 32 || &bytes[..2] != b\"\\x1f\\x8b\" {\n    bail!(\"not a plausible binlog (missing gzip header)\");\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"negative record length\") => {\n        warn!(\"binlog corrupt; regenerating\");\n        std::fs::remove_file(&binlog_path).ok();\n        rebuild_and_reparse()?;\n    }\n    other => other?,\n}","preventionTips":["Never feed non-binlog gzip files or renamed random files to the parser","Regenerate any binlog whose producing build was interrupted or failed mid-write","Verify artifact checksums/sizes when binlogs travel through CI uploads","Keep the parser and MSBuild versions aligned; unknown record types cause offset drift"],"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"}