rtk-ai/rtk · error · anyhow::Error
invalid 7-bit encoded integer
Error message
invalid 7-bit encoded integer
What it means
Raised by `read_7bit_i32` while decoding a .NET 7-bit variable-length (LEB128-style) integer: after shifting 35+ bits (more than 5 continuation bytes) the encoder still has not produced a terminating byte with the high bit clear. A valid 7-bit-encoded Int32 never exceeds 5 bytes, so this indicates corrupt data or a desynchronized read cursor. It is thrown from `read_dotnet_string` when decoding the string length prefix.
Solutions
- Confirm the input file is a genuine Binary Log produced by `dotnet build -bl`; regenerate it if in doubt.
- Check that earlier records were parsed with correct offsets — a misaligned cursor makes every subsequent 7-bit decode garbage; upgrade the reader if the binlog came from a newer SDK.
- Validate the decoded length immediately (see 'negative string length') and treat encoder failures as input corruption, aborting parse with context.
- Fall back to passthrough/raw output instead of failing the command when binlog parsing fails.
Defensive patterns
Strategy: validation
Validate before calling
// sanity-check before decoding: ensure at least 1 byte remains and
// cap the string-length prefix region to what the buffer can hold
fn can_decode_7bit(buf: &[u8], pos: usize) -> bool {
pos < buf.len() && buf[pos..].iter().take(5).count() > 0
} Try / catch
match read_dotnet_string(reader) {
Ok(s) => s,
Err(e) if e.to_string().contains("invalid 7-bit encoded integer") => {
eprintln!("binlog cursor desynchronized at offset {}", offset);
abort_parse_with_fallback()
}
Err(e) => return Err(e),
} Prevention
- Verify earlier record parses succeeded — a misaligned cursor corrupts every subsequent 7-bit decode.
- Confirm the input is a real binlog (magic bytes) before decoding strings.
- Cap look-ahead to 5 bytes when decoding so you fail fast on runaway continuation bytes.
- Test the parser against binlogs from the .NET SDK versions you actually use.
When it happens
Trigger: `read_dotnet_string` calls `read_7bit_i32` on bytes that are not a valid 7-bit encoding — e.g. 5+ consecutive bytes with the 0x80 bit set — typically because the cursor is misaligned or the buffer is not binlog data.
Common situations: Parsing a file that is not a real .binlog (wrong file passed); cursor misalignment after an earlier record was misparsed (format-version mismatch with a newer .NET SDK); corruption in the middle of a binlog; reading a partially flushed log.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- negative string length
- unexpected end of stream
- Failed to parse binlog at
- Failed to parse binlog at
- legacy dictionary format is unsupported
AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19).
Data as JSON: /api/errors/4199255865c03711.
Report an issue: GitHub.
Appendix: 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 0924356b4c)