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

  1. Regenerate the binlog from a clean build
  2. Verify the input file is a genuine .binlog (magic header) before parsing
  3. 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

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


AI-assisted analysis of rtk-ai/rtk@36788f6bd4 (2026-09-03). Data as JSON: /api/errors/4199255865c03711. Report an issue: GitHub.