Harden OperationBand index bounds and band-line parsing#229
Open
patrickrb wants to merge 1 commit into
Open
Conversation
Pre-store bug bash (PR 2 of the triage ledger). Three real defects in the band-list accessors, all reachable from the band/frequency pickers and the asset loader: - getBandFreq(int): the guard was `index > bandList.size()`, an off-by-one that let `index == size` fall through into `bandList.get(index)` and throw IndexOutOfBounds. Negative indices were unguarded too. - getBandInfo(int): returned `bandList.get(0)` whenever `index >= size`, which crashes when the list is empty (missing/corrupt bands.txt); negatives unguarded. - Band(String): a truncated line such as "20m:" passes isBandLine() (it has a colon) but splits to a single field, so the constructor threw and aborted the entire band-list load, leaving the app with no bands. Fixes centralise the bounds check in a single tested `isValidBandIndex()` helper used by every accessor, make getBandInfo fall back to the default band when the list is empty, and route the asset loader through a new `parseBandLines()` that logs and skips an individual malformed line instead of aborting the load. No behaviour change for valid input. Tests: OperationBandTest gains coverage for the off-by-one (index == size), negative indices, empty-list getBandInfo, and parseBandLines skipping truncated/non-numeric/comment/blank lines while keeping valid neighbours. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #229 +/- ##
==========================================
+ Coverage 8.28% 8.32% +0.03%
- Complexity 794 802 +8
==========================================
Files 289 289
Lines 32597 32606 +9
Branches 5197 5199 +2
==========================================
+ Hits 2702 2714 +12
+ Misses 29682 29679 -3
Partials 213 213
🚀 New features to boost your workflow:
|
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.
Context
First fix from the pre-app-store bug bash triage ledger (PR 2 — the highest-confidence cluster of real defects). Triage-verified by reading source; these are genuine crashers reachable from the band/frequency pickers and the
bands.txtasset loader.Bugs fixed
OperationBand.getBandFreq(int)index > size— off-by-one.index == sizeslipped through tobandList.get(index)→IndexOutOfBounds. Negatives unguarded.OperationBand.getBandInfo(int)bandList.get(0)whenindex >= size→ crashes on an empty list (missing/corruptbands.txt); negatives unguarded.OperationBand.Band(String)"20m:"passesisBandLine()(it has a colon) but splits to one field → constructor throws and aborts the entire band-list load, leaving the app with no bands.bands.txtApproach
isValidBandIndex()helper used by every accessor (rejects both negatives andindex >= size).getBandInfofalls back to the default band when the list is empty.parseBandLines(), which logs and skips an individual malformed line instead of aborting the whole load.Tests
OperationBandTest(now 34 tests, all green) gains coverage for: the off-by-one (index == size), negative indices on both accessors, empty-listgetBandInfo, andparseBandLinesskipping truncated / non-numeric / comment / blank lines while keeping valid neighbours.Run:
cmd.exe /c "gradlew.bat testDebugUnitTest --tests com.bg7yoz.ft8cn.database.OperationBandTest"🤖 Generated with Claude Code