fix(parser): stop panicking on malformed (and on some valid) lcov input - #1515
Open
Eljees wants to merge 1 commit into
Open
fix(parser): stop panicking on malformed (and on some valid) lcov input#1515Eljees wants to merge 1 commit into
Eljees wants to merge 1 commit into
Conversation
parse_lcov has a dedicated error path - the manage_parsing_error! macro and ParserError::InvalidRecord - but two unwrap() calls next to it panic instead of using it, even when the caller asked for lenient parsing. - The outer dispatch matches on the first byte of the line, so any record starting with 'e' (excluded_by_a_tool, or the checksum field of a DA:<line>,<count>,<checksum> record) took the end_of_record branch and hit cur_file.unwrap(). This is reachable from valid lcov files. - end_of_record before any SF: panicked instead of reporting InvalidRecord. - An unknown key longer than four uppercase letters panicked in lenient mode, because match key.unwrap() runs after manage_parsing_error! has only logged. Route all three through the existing error path and match the whole token in the end_of_record branch instead of one byte. Unknown records are skipped exactly like the ones already handled by the catch-all arm. Fixes mozilla#1511 Fixes mozilla#1501
Author
|
A note on the red All five clippy errors are outside the diff: This branch only touches If it would help, I am happy to send those five as a separate cleanup PR to get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1511. Also fixes #1501.
parse_lcovhas a dedicated error path — themanage_parsing_error!macro andParserError::InvalidRecord— but twounwrap()calls sitting next to it panic instead of using it. With lenient parsing (ignore_parsing_error = true) the panic happens even though the caller explicitly asked the parser not to fail.1. Any line starting with
ewas treated asend_of_record.The outer dispatch (
src/parser.rs:186) matches on the first byte of the line, soexcluded_by_a_tool— or any other record grcov does not know — took theend_of_recordbranch and hitcur_file.unwrap()on line 194. This is reachable from valid lcov files.The same byte-level dispatch is why
DA:<line>,<count>,<checksum>(the optional third field of aDArecord, standard lcov) crashes: theDAbranch stops after<count>, the checksume4f2is then read as the start of a new line, ande→ panic. That is issue #1501.2.
end_of_recordbefore anySF:panicked instead of reportingInvalidRecord.3. An unknown key longer than four uppercase letters panicked in lenient mode.
keyis already computed withchecked_mul/checked_addandmanage_parsing_error!is already called when it overflows — but in lenient mode the macro only logs, and the followingmatch key.unwrap()(line 231) panics anyway.The patch routes all three through the existing error path and makes the
end_of_recordbranch check the whole token instead of one byte. No new error semantics are introduced: unknown records are skipped exactly like the ones already handled by the catch-all arm.Six unit tests are added, in the style of the existing inline-buffer tests (
test_lcov_parser_empty_DA_record). Five of them panic onmaster.before / after
Not in this PR, tracked for a follow-up. #1511 also mentions the hand-rolled decimal folds. They are genuinely reachable, but only from input no producer emits, and fixing them touches seven call sites, so I kept the diff focused. Reproducers, all panicking on
mastertoday:Happy to send that as a second PR (or fold it in here) if you prefer.
AI-assisted: I used Claude to help map the panic sites and to draft the patch and the tests. I reviewed every line, ran each new test against unpatched
masterfirst to confirm it panics without the fix, and rancargo fmt --checkandcargo clippy -- -D warningsper the repo's pre-commit config; the analysis and the runs are mine.