Skip to content

Fix issue 464: Add multiple checking condition to avoid IOOBE #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2289,7 +2289,9 @@ protected void _finishToken() throws IOException
// 29-Jan-2021, tatu: as per [dataformats-binary#238] must keep in mind that
// the longest individual unit is 4 bytes (surrogate pair) so we
// actually need len+3 bytes to avoid bounds checks
final int needed = len + 3;
// 18-Jan-2024, tatu: For malicious input / Fuzzers, need to worry about overflow
// like Integer.MAX_VALUE
final int needed = Math.max(len, len + 3);
final int available = _inputEnd - _inputPtr;

if ((available >= needed)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fasterxml.jackson.dataformat.cbor.fuzz;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.exc.StreamReadException;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.fasterxml.jackson.dataformat.cbor.CBORTestBase;

public class CBORFuzz464_65722_IOOBETest extends CBORTestBase
{
private final ObjectMapper MAPPER = cborMapper();

public void testInvalidText() throws Exception
{
final byte[] input = {
(byte)-60, (byte)-49, (byte)122, (byte)127, (byte)-1,
(byte)-1, (byte)-1, (byte)15, (byte)110
};
try (JsonParser p = MAPPER.createParser(input)) {
try {
assertToken(JsonToken.VALUE_STRING, p.nextToken());
// oddly enough `getText()` didn't do it but this:
p.getTextLength();
fail("Should not reach here (invalid input)");
} catch (StreamReadException e) {
verifyException(e, "Unexpected end-of-input in VALUE_STRING");
}
}
}
}
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,6 @@ Arthur Chan (@arthurscchan)
(2.17.0)
* Contributed #460: (protobuf) Unexpected `NullPointerException` in `ProtobufParser.currentName()`
(2.17.0)
* Contributed #464: (cbor) Unexpected `ArrayIndexOutOfBoundsException` in `CBORParser`
for corrupt String value
(2.17.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Active maintainers:
#460: (protobuf) Unexpected `NullPointerException` in `ProtobufParser.currentName()`
(fix contributed by Arthur C)
#462: (protobuf) `ProtobufParser.currentName()` returns wrong value at root level
#464: (cbor) Unexpected `ArrayIndexOutOfBoundsException` in `CBORParser`
for corrupt String value
(fix contributed by Arthur C)
- (ion) Update `com.amazon.ion:ion-java` to 1.11.0 (from 1.10.5)

2.16.1 (24-Dec-2023)
Expand Down