Repository navigation
fix(sdcard): guard CSV data-start detection against a bare "ch" line (closes #365) - #366
Conversation
…loses #365) FindDataStartIndex accessed line[2] whenever a line started with "ch", but StartsWith("ch") only guarantees length >= 2. A bare "ch" line (length 2) threw IndexOutOfRangeException, which propagated out of ParseAsync/ParseFileAsync and aborted the entire parse — violating the parser's skip-bad-lines contract that every other line-parsing method upholds. Add a line.Length > 2 guard before the line[2] access. Behavior is unchanged for all lines of length >= 3 (the only case where line[2] was previously valid); a too-short "ch" line now falls through and is treated as a data row, which TryParseCsvDataRow skips as malformed. Two regression tests: a bare "ch" line between valid rows parses the valid rows without throwing, and a file whose only data line is "ch" yields zero samples without throwing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
/agentic_review |
PR Summary by QodoGuard SdCard CSV data-start detection against bare "ch" line
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
ParseHeader and FindDataStartIndex used divergent "ch" predicates after the #365 crash fix: ParseHeader stopped on any StartsWith("ch") line while FindDataStartIndex's guarded predicate treated a bare "ch" as a data row. A stray "ch" before the real column header therefore silently mis-parsed — the real header was skipped as a bad row, channel counts came out 0, and the dio column was misclassified as an extra analog value. Extract a shared IsColumnHeaderLine predicate and an IsHeaderNoiseLine helper; both the header parser and the data-start scan now skip malformed "ch" header-region noise and land on the real header. No public API change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
/agentic_review |
|
Code review by qodo was updated up to the latest commit 4d92522 |
|
Ready for review: Qodo re-review is clean (0 bugs / 0 rule violations, updated to the latest commit 4d92522, the one review thread resolved) and CI |
Summary
SdCardCsvFileParser.FindDataStartIndexaccessedline[2]whenever a line started with"ch", butStartsWith("ch")only guarantees length >= 2. A bare"ch"line (exactly 2 chars) threwIndexOutOfRangeException, which — becauseFindDataStartIndexis called synchronously insideParseAsync— propagated out ofParseAsync/ParseFileAsyncand aborted the whole parse.This violated the parser's own robustness contract: every other line-parsing method (
TryParseCsvDataRow,TryParseJsonLine) wraps parsing so malformed input is skipped gracefully.FindDataStartIndexwas the single place that could crash on malformed/truncated SD log content.Fix
Add a
line.Length > 2guard before theline[2]access. Behavior is unchanged for every line of length >= 3 (the only case whereline[2]was previously valid). A too-short"ch"line now falls through and is treated as a data row, whichTryParseCsvDataRowthen skips as malformed — consistent with how all other bad lines are handled.Tests
ParseAsync_BareChLine_DoesNotThrowAndParsesRemainingRows— a bare"ch"line between valid rows: valid rows still parse, no throw.ParseAsync_OnlyBareChLine_ReturnsNoSamplesWithoutThrowing— a file whose only data line is"ch": zero samples, no throw.Both fail with
IndexOutOfRangeExceptionbefore the fix (verified by reverting the source change) and pass after.Validation
Closes #365.
Not merging — opened for your review.
🤖 Generated with Claude Code