Fix FlexRadio meter-list parse crash on frame without "meter " keyword#491
Merged
Merged
Conversation
FlexMeterInfos.setMeterInfos() parsed the meter definition list with
content.substring(content.indexOf("meter ") + 6)
and no guard on the indexOf() result. When a corrupt or truncated
METER_LIST frame does not contain "meter ", indexOf() returns -1, so
the offset becomes 5 and substring(5) throws
StringIndexOutOfBoundsException on any frame shorter than 5 chars.
This runs on the FlexRadio TCP read thread (RadioTcpClient.SocketThread),
whose read loop catches only SocketException/IOException, so the
RuntimeException escapes and crashes the whole app.
Root cause: missing validation that the "meter " keyword is present
before slicing the string. Fix returns early when the keyword is absent
(a non-meter frame has no meter definitions to parse), which also stops
non-meter frames from being parsed as garbage.
Adds FlexMeterInfosTest (pure JVM) covering the crash regression, empty
input, keyword-at-end, non-meter frames, well-formed parsing, and
in-place re-parse.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #491 +/- ##
=========================================
Coverage 23.35% 23.35%
Complexity 162 162
=========================================
Files 167 167
Lines 21450 21450
Branches 3154 3154
=========================================
Hits 5009 5009
Misses 16248 16248
Partials 193 193
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR hardens the FlexRadio METER_LIST parser to avoid an app-crashing StringIndexOutOfBoundsException when a response frame is corrupt/truncated and lacks the "meter " keyword, and adds JVM unit tests to prevent regressions.
Changes:
- Add a guard in
FlexMeterInfos.setMeterInfos()to return early when"meter "is missing before slicing/parsing. - Add a new pure-JVM
FlexMeterInfosTestcovering the crash regression and validating well-formed parsing behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| ft8af/app/src/main/java/com/k1af/ft8af/flex/FlexMeterInfos.java | Adds a safe "meter " presence check to prevent substring-based crashes on malformed frames. |
| ft8af/app/src/test/java/com/k1af/ft8af/flex/FlexMeterInfosTest.java | Adds unit tests for malformed/non-meter frames and for correct parsing of a representative meter list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
FlexMeterInfos.setMeterInfos()can throw an uncaughtStringIndexOutOfBoundsExceptionand crash the entire app when a FlexRadioMETER_LISTresponse frame is corrupt or truncated.Root cause
The parser sliced the meter-definition list with:
with no guard on the
indexOf()result. Whencontentdoes not contain"meter ",indexOf()returns-1, so the offset becomes-1 + 6 = 5, andsubstring(5)throwsStringIndexOutOfBoundsExceptionfor any frame shorter than 5 characters (e.g."0").This parse runs on the FlexRadio TCP read thread (
RadioTcpClient.SocketThread.run()), whose read loop catches onlySocketException/IOException:A
RuntimeExceptiontherefore propagates out of the read thread uncaught → Android's default handler terminates the process. Same failure class as the previously fixed Xiegu handle (PR #488) and Icom/Kenwood/Yaesu CAT parser crashes (PRs #487/#489): a rig-response parser that trusts the shape of untrusted serial/network input.Fix
Validate that the
"meter "keyword is present before slicing; if it is not, return early (a non-meter frame carries no meter definitions to parse). This is the smallest safe change and additionally prevents a long non-meter frame from being mis-parsed as garbage meter definitions.No protocol behavior changes for well-formed meter lists.
Testing
FlexMeterInfosTest(pure JVM, no Robolectric —FlexMeterInfostouches no Android types):shortFrameWithoutMeterKeyword_doesNotCrash— the crash regression; fails withStringIndexOutOfBoundsExceptionon the pre-fix code, passes after.parsesWellFormedMeterList— confirms ids (sMeterId/swrId/pwrId/alcId/tempCId), unit mapping, and numeric fields still parse correctly.emptyContent_isNoOp,frameWithoutMeterKeyword_isIgnored,meterKeywordAtEnd_doesNotCrash,reparseUpdatesExistingDefinitions.shortFrameWithoutMeterKeyword_doesNotCrash../gradlew :app:testDebugUnitTest— full suite BUILD SUCCESSFUL../gradlew :app:assembleDebug(native/cmake included) — BUILD SUCCESSFUL.Risk assessment
Very low. One-file guard on a single parse path; no DSP, encoder/decoder, waterfall, or audio code touched. Well-formed frames are unaffected; the only behavior change is that malformed/non-meter frames are now ignored instead of crashing (or being parsed as junk).
Affected platforms
All (FlexRadio 6xxx TCP CAT path).
🤖 Generated with Claude Code