{"record":{"id":"f8a75596dce35f30","repo":"rtk-ai/rtk","slug":"negative-string-length","errorCode":null,"errorMessage":"negative string length: {}","messagePattern":"negative string length: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/cmds/dotnet/binlog.rs","lineNumber":631,"sourceCode":"        let mut shift = 0;\n        loop {\n            let byte = self.read_u8()?;\n            value |= ((byte & 0x7F) as u32) << shift;\n            if (byte & 0x80) == 0 {\n                return Ok(value as i32);\n            }\n\n            shift += 7;\n            if shift >= 35 {\n                anyhow::bail!(\"invalid 7-bit encoded integer\");\n            }\n        }\n    }\n\n    fn read_dotnet_string(&mut self) -> Result<String> {\n        let len = self.read_7bit_i32()?;\n        if len < 0 {\n            anyhow::bail!(\"negative string length: {}\", len);\n        }\n        let bytes = self.read_exact(len as usize)?;\n        String::from_utf8(bytes.to_vec()).context(\"invalid UTF-8 string\")\n    }\n}\n\npub fn scrub_sensitive_env_vars(input: &str) -> String {\n    SENSITIVE_ENV_RE\n        .replace_all(input, \"${prefix}[REDACTED]\")\n        .into_owned()\n}\n\npub fn parse_build_from_text(text: &str) -> BuildSummary {\n    let text = text.replace(\"\\r\\n\", \"\\n\");\n    let clean = strip_ansi(&text);\n    let scrubbed = scrub_sensitive_env_vars(&clean);\n    let mut seen_errors: HashSet<(String, String, u32, u32, String)> = HashSet::new();\n    let mut seen_warnings: HashSet<(String, String, u32, u32, String)> = HashSet::new();","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/rtk-ai/rtk/blob/36788f6bd4932037caac5cbb1d15d6e2fb9f33da/src/cmds/dotnet/binlog.rs#L613-L649","documentation":"read_dotnet_string decodes a 7-bit length then reads that many bytes as UTF-8. A negative length is impossible for a valid string, so it means the stream is corrupt or the reader is desynchronized. The subsequent read_exact would also fail on absurd lengths.","triggerScenarios":"An event field containing a string whose encoded length decodes negative, occurring during read_event_fields driven by parse_events_from_binlog — corrupt payload or mid-stream misalignment.","commonSituations":"Truncated/partially written binlogs; non-binlog files fed to the parser; corrupted artifacts transferred between machines.","solutions":["Regenerate the binlog — treat this file as corrupt","Check integrity (checksum) if the file came from CI or a share","Confirm it is a binlog (magic header), not a misnamed file"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match parse_events_from_binlog(&path) {\n    Ok(b) => use_events(&b),\n    Err(e) if e.to_string().contains(\"negative string length\") => {\n        eprintln!(\"binlog corrupt; regenerate from a clean build\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Checksum artifacts transferred between machines","Ensure builds finish before parsing logs","Verify the input is a real binlog, not a misnamed file"],"tags":["dotnet","binlog","corruption","deserialization"],"backgroundTag":"corrupt-or-truncated-log-file","analyzedSha":"36788f6bd4932037caac5cbb1d15d6e2fb9f33da","analyzedAt":"2026-09-03T16:33:57.738Z","contentChangedAt":"2026-09-03T16:33:57.738Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}