rtk-ai/rtk · error · anyhow::Error
invalid 7-bit encoded integer
Error message
invalid 7-bit encoded integer
What it means
read_7bit_i32 decodes a 7-bit variable-length integer; if it still hasn't seen a terminating byte after 5 bytes (shift >= 35), the encoding is invalid for an i32 and parsing bails. This signals misaligned/corrupt stream data at the string-reading site.
Source
Thrown at src/cmds/dotnet/binlog.rs:623
let b = self.read_exact(8)?;
Ok(i64::from_le_bytes([
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7],
]))
}
fn read_7bit_i32(&mut self) -> Result<i32> {
let mut value: u32 = 0;
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()View on GitHub (pinned to 36788f6bd4)
Solutions
- Regenerate the binlog from a clean build
- Verify the input file is a genuine .binlog (magic header) before parsing
- If reproducible on a file that opens in Structured Log Viewer, file a parser bug with the offending record
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("invalid 7-bit encoded integer") => {
eprintln!("binlog stream corrupt; regenerate the log");
}
Err(e) => return Err(e),
} Prevention
- Validate the binlog magic header before parsing
- Regenerate corrupt logs rather than retrying
- Report reproducible failures with the offending file to the tool maintainers
When it happens
Trigger: read_dotnet_string calls read_7bit_i32 on bytes that are not a valid 7-bit-encoded length — the cursor is in the middle of arbitrary data (misalignment from earlier corruption) or the file is not a binlog.
Common situations: Parsing corrupted/truncated binlogs; passing random binary or text files as .binlog; version mismatch causing a wrong offset interpretation.
Related errors
- negative record length: {}
- negative event length: {}
- negative string length: {}
- 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/4199255865c03711.
Report an issue: GitHub.