You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "arthurscchan (via GitHub)" <gi...@apache.org> on 2023/11/23 21:43:33 UTC
[PR] CODEC-315: Fix possible IndexOutOfBoundException [commons-codec]
arthurscchan opened a new pull request, #223:
URL: https://github.com/apache/commons-codec/pull/223
This fixes possible StringIndexOutOfBoundsException and ArrayIndexOutOfBoundsException in [src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java](https://github.com/apache/commons-codec/blob/master/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java)
This PR fixes the parameter for the split method and adds a conditional check to ensure only strings and arrays are not empty before processing.
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=64376 and https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=64395.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException [commons-codec]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #223:
URL: https://github.com/apache/commons-codec/pull/223#discussion_r1404339328
##########
src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java:
##########
@@ -70,4 +80,13 @@ public void testEncode(final String name, final String phoneticExpected, final N
}
}
}
+
+ @ParameterizedTest
+ @MethodSource("invalidData")
+ public void testInvalidEncode(final String input, final NameType nameType, final RuleType ruleType,
+ final boolean concat, final int maxPhonemes) {
+ final PhoneticEngine engine = new PhoneticEngine(nameType, ruleType, concat, maxPhonemes);
+
+ assertDoesNotThrow(() -> engine.encode(input));
Review Comment:
Why is `assertDoesNotThrow` used here? The test method does nothing else after the call to encode so there is nothing else to run. Or, am I missing something?
Note: I am not going to copy-paste the above comment in all PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException [commons-codec]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #223:
URL: https://github.com/apache/commons-codec/pull/223#discussion_r1404340973
##########
src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java:
##########
@@ -431,7 +431,7 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
} else if (words2.size() == 1) {
// not a multi-word name
input = words.iterator().next();
- } else {
+ } else if (words2.size() > 0) {
Review Comment:
Use `isEmpty()`.
##########
src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java:
##########
@@ -70,4 +80,13 @@ public void testEncode(final String name, final String phoneticExpected, final N
}
}
}
+
+ @ParameterizedTest
+ @MethodSource("invalidData")
+ public void testInvalidEncode(final String input, final NameType nameType, final RuleType ruleType,
+ final boolean concat, final int maxPhonemes) {
+ final PhoneticEngine engine = new PhoneticEngine(nameType, ruleType, concat, maxPhonemes);
+
+ assertDoesNotThrow(() -> engine.encode(input));
Review Comment:
Why is `assertDoesNotThrow` used here? The test method does nothing else after the call to encode so there is nothing else to run. Or, am I missing something?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException [commons-codec]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #223:
URL: https://github.com/apache/commons-codec/pull/223#issuecomment-1825661894
@arthurscchan
Please use a better description in PRs and JIRA: Specify the class and method where the exception occurs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException thrown by PhoneticEngine.encode method [commons-codec]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #223:
URL: https://github.com/apache/commons-codec/pull/223
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException thrown by PhoneticEngine.encode method [commons-codec]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #223:
URL: https://github.com/apache/commons-codec/pull/223#issuecomment-1826180476
## [Codecov](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: `1 lines` in your changes are missing coverage. Please review.
> Comparison is base [(`44e4c4d`)](https://app.codecov.io/gh/apache/commons-codec/commit/44e4c4d778c3ab87db09c00e9d1c3260fd42dad5?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 92.27% compared to head [(`ee02460`)](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) 92.27%.
> Report is 2 commits behind head on master.
| [Files](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [...ache/commons/codec/language/bm/PhoneticEngine.java](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2NvbW1vbnMvY29kZWMvbGFuZ3VhZ2UvYm0vUGhvbmV0aWNFbmdpbmUuamF2YQ==) | 50.00% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #223 +/- ##
=========================================
Coverage 92.27% 92.27%
- Complexity 1742 1743 +1
=========================================
Files 67 67
Lines 4584 4585 +1
Branches 709 710 +1
=========================================
+ Hits 4230 4231 +1
Misses 242 242
Partials 112 112
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/commons-codec/pull/223?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CODEC-315: Fix possible IndexOutOfBoundException [commons-codec]
Posted by "arthurscchan (via GitHub)" <gi...@apache.org>.
arthurscchan commented on code in PR #223:
URL: https://github.com/apache/commons-codec/pull/223#discussion_r1404619881
##########
src/test/java/org/apache/commons/codec/language/bm/PhoneticEngineTest.java:
##########
@@ -70,4 +80,13 @@ public void testEncode(final String name, final String phoneticExpected, final N
}
}
}
+
+ @ParameterizedTest
+ @MethodSource("invalidData")
+ public void testInvalidEncode(final String input, final NameType nameType, final RuleType ruleType,
+ final boolean concat, final int maxPhonemes) {
+ final PhoneticEngine engine = new PhoneticEngine(nameType, ruleType, concat, maxPhonemes);
+
+ assertDoesNotThrow(() -> engine.encode(input));
Review Comment:
Originally I just want to test if the invalid input still throw any unexpected exceptions. But yes, I do agree the result also needed to be checked. I have changed the test case a little bit, as well as for other PRs. Thanks for your suggestions.
##########
src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java:
##########
@@ -431,7 +431,7 @@ public String encode(String input, final Languages.LanguageSet languageSet) {
} else if (words2.size() == 1) {
// not a multi-word name
input = words.iterator().next();
- } else {
+ } else if (words2.size() > 0) {
Review Comment:
Changed. Thanks for your suggestion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org