Skip to content

CODEC-313: Fix possible ArrayIndexOutOfBoundsException thrown by QuotedPrintableCodec.encodeQuotedPrintable() method#221

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

CODEC-313: Fix possible ArrayIndexOutOfBoundsException thrown by QuotedPrintableCodec.encodeQuotedPrintable() method#221
garydgregory merged 2 commits into
apache:masterfrom
arthurscchan:CODEC-313-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/QuotedPrintableCodec.java thrown by QuotedPrintableCodec.encodeQuotedPrintable() method when the input byte array has less than 3 elements.

This PR adds a conditional check to ensure the index is never negative. It will simply return null if the byte array is too short (with a length less than 3) if strict value is true.

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=64358.

@garydgregory

Copy link
Copy Markdown
Member

@arthurscchan
You'll need a unit test to prove what the main change does.

@arthurscchan

Copy link
Copy Markdown
Contributor Author

Hi, I have added the unit test.

@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.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arthurscchan
Please see my comment.

Comment thread src/main/java/org/apache/commons/codec/net/QuotedPrintableCodec.java Outdated
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@arthurscchan arthurscchan force-pushed the CODEC-313-ArrayIndexOutOfBound branch from 4769376 to ad656e5 Compare November 24, 2023 19:10
@arthurscchan arthurscchan changed the title CODEC-313: Fix possible ArrayIndexOutOfBoundsException CODEC-313: Fix possible ArrayIndexOutOfBoundsException thrown by QuotedPrintableCodec.encodeQuotedPrintable() method Nov 24, 2023
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
@arthurscchan arthurscchan force-pushed the CODEC-313-ArrayIndexOutOfBound branch from ad656e5 to 130dafc Compare November 24, 2023 20:20
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (44e4c4d) 92.27% compared to head (130dafc) 92.28%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #221   +/-   ##
=========================================
  Coverage     92.27%   92.28%           
- Complexity     1742     1743    +1     
=========================================
  Files            67       67           
  Lines          4584     4586    +2     
  Branches        709      710    +1     
=========================================
+ Hits           4230     4232    +2     
  Misses          242      242           
  Partials        112      112           

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

@garydgregory garydgregory merged commit c65de5c into apache:master Nov 25, 2023
@garydgregory

Copy link
Copy Markdown
Member

@arthurscchan
TY, merged. It looks like encoder exceptions are not in play here.

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
…edPrintableCodec.encodeQuotedPrintable() method (apache#221)

* CODEC-313: Fix possible ArrayIndexOutOfBoundsException

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

* CODEC-313: Add unit test

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

---------

Signed-off-by: Arthur Chan <arthur.chan@adalogics.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