Skip to content

CODEC-311: Fix possible ArrayIndexOutOfBoundException thrown by RefinedSoundex.getMappingCode()#219

Merged
garydgregory merged 3 commits into
apache:masterfrom
arthurscchan:CODEC-311-ArrayIndexOutOfBound
Nov 25, 2023
Merged

CODEC-311: Fix possible ArrayIndexOutOfBoundException thrown by RefinedSoundex.getMappingCode()#219
garydgregory merged 3 commits into
apache:masterfrom
arthurscchan:CODEC-311-ArrayIndexOutOfBound

Conversation

@arthurscchan

@arthurscchan arthurscchan commented Nov 22, 2023

Copy link
Copy Markdown
Contributor

This fixes a possible ArrayIndexOutOfBoundException in src/main/java/org/apache/commons/codec/language/RefinedSoundex.java thrown by RefinedSoundex.getMappingCode() method when handling out of range letters.

This PR adds a conditional checking to ensure the index is never out of bounds from the configured soundexMapping array. If the calculated index goes out of bounds, it will simply return 0, just like the original logic when Character.isLetter() returns false.

We found this bug using fuzzing by way of OSS-Fuzz. It is reported at https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64353.

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@garydgregory

Copy link
Copy Markdown
Member

Hello @arthurscchan
You'll need a unit test to prove this change works.

@arthurscchan

Copy link
Copy Markdown
Contributor Author

@garydgregory Thanks for the comment. I have added a unit test.

@codecov-commenter

codecov-commenter commented Nov 22, 2023

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.22%. Comparing base (44e4c4d) to head (a9c487e).
⚠️ Report is 933 commits behind head on master.

Files with missing lines Patch % Lines
.../apache/commons/codec/language/RefinedSoundex.java 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #219      +/-   ##
============================================
- Coverage     92.27%   92.22%   -0.05%     
- Complexity     1742     1747       +5     
============================================
  Files            67       67              
  Lines          4584     4594      +10     
  Branches        709      714       +5     
============================================
+ Hits           4230     4237       +7     
- Misses          242      243       +1     
- Partials        112      114       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/test/java/org/apache/commons/codec/language/RefinedSoundexTest.java Outdated
@arthurscchan arthurscchan force-pushed the CODEC-311-ArrayIndexOutOfBound branch 2 times, most recently from 9abdfbb to e1fa662 Compare November 22, 2023 20:06
@garydgregory

Copy link
Copy Markdown
Member

@arthurscchan
Please use a better description in PRs and JIRA: Specify the class and method where the exception occurs.

@arthurscchan arthurscchan changed the title CODEC-311: Fix possible ArrayIndexOutOfBoundException CODEC-311: Fix possible ArrayIndexOutOfBoundException thrown from RefinedSoundex.getMappingCode() Nov 24, 2023
@arthurscchan arthurscchan changed the title CODEC-311: Fix possible ArrayIndexOutOfBoundException thrown from RefinedSoundex.getMappingCode() CODEC-311: Fix possible ArrayIndexOutOfBoundException thrown by RefinedSoundex.getMappingCode() Nov 24, 2023
@arthurscchan arthurscchan force-pushed the CODEC-311-ArrayIndexOutOfBound branch from e1fa662 to 0294b50 Compare November 24, 2023 18:24
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@arthurscchan arthurscchan force-pushed the CODEC-311-ArrayIndexOutOfBound branch from 0294b50 to f33a657 Compare November 24, 2023 20:08
@garydgregory garydgregory merged commit 29012d7 into apache:master Nov 25, 2023
garydgregory added a commit that referenced this pull request Nov 25, 2023
omosteven pushed a commit to omosteven/commons-codec-lab-work that referenced this pull request Jan 8, 2025
…edSoundex.getMappingCode() (apache#219)

* CODEC-311: Fix possible ArrayIndexOutOfBoundException

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

* CODEC-311: Add unit test

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>

* Use final

---------

Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
Co-authored-by: Gary Gregory <garydgregory@users.noreply.github.com>
omosteven pushed a commit to omosteven/commons-codec-lab-work that referenced this pull request Jan 8, 2025
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.

3 participants