Skip to content

fix(core): preserve dominator num assignment and guard cycles in SwitchOverStringVisitor - #3084

Merged
skylot merged 4 commits into
skylot:masterfrom
arrteann:fix/switch-over-string-idom-cycle
Nov 19, 2026
Merged

skylot merged 4 commits into
skylot:masterfrom
arrteann:fix/switch-over-string-idom-cycle

Conversation

@arrteann

Copy link
Copy Markdown
Contributor

Summary

  • Fix dominator numValue overwrite in SwitchOverStringVisitor: When searching thenBlock.getIDom() for the switch-over-string index assignment, subsequent non-matching instructions in the same dominator block (such as String.hashCode()) previously overwrote numValue back to null. Only update numValue when extractConstNumber returns a non-null value.
  • Guard against cycles & empty-arg instructions:
    • Add visited-block guards in collectIfSwitchHashes and collectStringCases to prevent infinite loops on malformed/obfuscated CFGs.
    • Add zero-allocation cycle detection in getOnlyOneInsnBlock for empty-block loops.
    • Check strHashInsn.getArgsCount() > 0 before calling getArg(0) to avoid spurious IndexOutOfBoundsException warning comments.
  • Readability refactor: Split collectPart1RegionCases into focused helpers (collectIfSwitchHashes, collectSwitchHashes, collectStringCases, resolveCaseNumValue) and iterate hashCases.entrySet().

Tests

  • Added TestSwitchOverStrings6 (TestSwitchOverStrings6.smali) covering num assignment in iDom before String.hashCode().
  • Ran ./gradlew :jadx-core:test --tests "jadx.tests.integration.switches.*" — all tests passed.

@arrteann

Copy link
Copy Markdown
Contributor Author

Fixed the spotless formatting issue, ready for CI re-run.

@skylot
skylot merged commit 5a3a1fa into skylot:master Nov 19, 2026
2 checks passed
@arrteann
arrteann deleted the fix/switch-over-string-idom-cycle branch November 19, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants