{"record":{"id":"82740c326d9feb80","repo":"rust-lang/rust","slug":"unparsed-bytes-0x-02x","errorCode":null,"errorMessage":"unparsed bytes: 0x{:02x?}","messagePattern":"unparsed bytes: 0x(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/coverage-dump/src/parser.rs","lineNumber":13,"sourceCode":"use anyhow::ensure;\n\npub(crate) struct Parser<'a> {\n    rest: &'a [u8],\n}\n\nimpl<'a> Parser<'a> {\n    pub(crate) fn new(input: &'a [u8]) -> Self {\n        Self { rest: input }\n    }\n\n    pub(crate) fn ensure_empty(self) -> anyhow::Result<()> {\n        ensure!(self.rest.is_empty(), \"unparsed bytes: 0x{:02x?}\", self.rest);\n        Ok(())\n    }\n\n    pub(crate) fn read_n_bytes(&mut self, n: usize) -> anyhow::Result<&'a [u8]> {\n        ensure!(n <= self.rest.len());\n\n        let (bytes, rest) = self.rest.split_at(n);\n        self.rest = rest;\n        Ok(bytes)\n    }\n\n    pub(crate) fn read_uleb128_u32(&mut self) -> anyhow::Result<u32> {\n        self.read_uleb128_u64_and_convert()\n    }\n\n    pub(crate) fn read_uleb128_usize(&mut self) -> anyhow::Result<usize> {\n        self.read_uleb128_u64_and_convert()\n    }","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/coverage-dump/src/parser.rs#L1-L31","documentation":"Raised by Parser::ensure_empty when, after consuming all expected fields of a coverage record, self.rest still contains trailing bytes. It is a structural integrity check: the parser's read sequence did not account for every byte in the input, meaning either an unknown extension field or a misparse occurred.","triggerScenarios":"Called at the end of parsing a coverage data structure (e.g. after reading all function records / counter expressions) when ensure_empty() is invoked on the Parser. Triggers when the LLVM coverage format version adds fields this coverage-dump does not know about, or when a preceding read_uleb128 under-read a length-prefixed region.","commonSituations":"Upgrading rustc/LLVM to a version that extended the coverage mapping format while coverage-dump is pinned to an older revision; manually crafted or fuzzed coverage inputs; a bug where a length field is read as u32 but the body is shorter, leaving leftover bytes.","solutions":["Rebuild coverage-dump from the same commit as the rustc that emitted the coverage data.","Inspect the leftover bytes (0x..) for a recognizable LLVM coverage record tag to identify the new field.","Check rust-lang/rust for recent changes to coverage mapping versioning (CoverageMappingVersion).","Re-generate the coverage data with a toolchain matching coverage-dump's expected format version."],"exampleFix":"// before: bail on any leftover bytes\nensure!(self.rest.is_empty(), \"unparsed bytes: 0x{:02x?}\", self.rest);\n\n// after: tolerate unknown trailing bytes with a warning when forward-compat is desired\nif !self.rest.is_empty() {\n    tracing::warn!(\"unparsed {} trailing bytes: 0x{:02x?}\", self.rest.len(), self.rest);\n}\n// (only do this if the format explicitly permits future extensions)","handlingStrategy":"validation","validationCode":"// If you feed coverage-dump programmatically, verify the format version header\n// matches what your coverage-dump build expects before parsing:\nif coverage_format_version(&bytes) != SUPPORTED_VERSION {\n    return Err(anyhow!(\"coverage format {} unsupported by this coverage-dump\",\n        coverage_format_version(&bytes)));\n}","typeGuard":"null","tryCatchPattern":"match parser.ensure_empty() {\n    Ok(()) => Ok(parsed),\n    Err(e) => {\n        tracing::warn!(\"parser left trailing bytes; coverage format may be newer: {e}\");\n        Ok(parsed) // only if forward-compat is acceptable for your use\n    }\n}","preventionTips":["Keep coverage-dump at the same commit as the rustc that emitted the data.","Add a coverage-format-version check before invoking the detailed parser.","Treat unparsed-bytes warnings as a signal to upgrade, not noise."],"tags":["coverage","llvm","parser","version-mismatch"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}