Skip to content

Fix possible ArrayIndexOutOfBoundsException#218

Closed
arthurscchan wants to merge 1 commit intoapache:masterfrom
arthurscchan:fix-64358
Closed

Fix possible ArrayIndexOutOfBoundsException#218
arthurscchan wants to merge 1 commit intoapache:masterfrom
arthurscchan:fix-64358

Conversation

@arthurscchan
Copy link
Contributor

This fixes a possible ArrayIndexOutOfBoundException in src/main/java/org/apache/commons/codec/language/QuotedPrintableCodec.java

The encodeQuotedPrintable() method takes in a random byte array and processes it. If the provided strict boolean is true, it will go into the first branch. There is a for loop to loop through the byte array from the index 0 to the index byte.length - 3. The index is then used directly in getUnsignedOctet method If the length of the byte array is less than 3, it will result in a negative index and cause ArrayIndexOutOfBoundsException in getUnsignedOctet() method call.

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.

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

1 participant