rtk-ai/rtk · error · anyhow::Error
negative string length: {}
Error message
negative string length: {} What it means
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.
Source
Thrown at src/cmds/dotnet/binlog.rs:631
let mut shift = 0;
loop {
let byte = self.read_u8()?;
value |= ((byte & 0x7F) as u32) << shift;
if (byte & 0x80) == 0 {
return Ok(value as i32);
}
shift += 7;
if shift >= 35 {
anyhow::bail!("invalid 7-bit encoded integer");
}
}
}
fn read_dotnet_string(&mut self) -> Result<String> {
let len = self.read_7bit_i32()?;
if len < 0 {
anyhow::bail!("negative string length: {}", len);
}
let bytes = self.read_exact(len as usize)?;
String::from_utf8(bytes.to_vec()).context("invalid UTF-8 string")
}
}
pub fn scrub_sensitive_env_vars(input: &str) -> String {
SENSITIVE_ENV_RE
.replace_all(input, "${prefix}[REDACTED]")
.into_owned()
}
pub fn parse_build_from_text(text: &str) -> BuildSummary {
let text = text.replace("\r\n", "\n");
let clean = strip_ansi(&text);
let scrubbed = scrub_sensitive_env_vars(&clean);
let mut seen_errors: HashSet<(String, String, u32, u32, String)> = HashSet::new();
let mut seen_warnings: HashSet<(String, String, u32, u32, String)> = HashSet::new();View on GitHub (pinned to 36788f6bd4)
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
Defensive patterns
Strategy: try-catch
Try / catch
match parse_events_from_binlog(&path) {
Ok(b) => use_events(&b),
Err(e) if e.to_string().contains("negative string length") => {
eprintln!("binlog corrupt; regenerate from a clean build");
}
Err(e) => return Err(e),
} Prevention
- Checksum artifacts transferred between machines
- Ensure builds finish before parsing logs
- Verify the input is a real binlog, not a misnamed file
When it happens
Trigger: 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.
Common situations: Truncated/partially written binlogs; non-binlog files fed to the parser; corrupted artifacts transferred between machines.
Related errors
- negative record length: {}
- negative event length: {}
- invalid 7-bit encoded integer
- unexpected end of stream
- Failed to parse binlog at {}: empty file
AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03).
Data as JSON: /api/errors/f8a75596dce35f30.
Report an issue: GitHub.