Skip to content
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

Fixed #434: Add null check before accessing integer size #435

Merged
merged 8 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -397,7 +397,15 @@ public NumberType getNumberType() throws IOException
//Ion decimals can be arbitrary precision, need to read as big decimal
return NumberType.BIG_DECIMAL;
case INT:
IntegerSize size = _reader.getIntegerSize();
IntegerSize size = null;
try {
size = _reader.getIntegerSize();
} catch (NullPointerException e) {
// Possible exception
Copy link
Member

Choose a reason for hiding this comment

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

Hmmh. I assume this is due to invalid/malformer content; and if so, should error out instead of quietly swallowing. Especially since it will fail couple of lines anyway. I can change that.

}
arthurscchan marked this conversation as resolved.
Show resolved Hide resolved
if (size == null) {
_reportError("Current token (%s) not integer", _currToken);
}
switch (size) {
case INT:
return NumberType.INT;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.fasterxml.jackson.dataformat.ion.fuzz;

import java.io.*;

import org.hamcrest.Matchers;
import org.junit.Test;

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.ion.*;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

// [dataformats-binary#434
public class Fuzz434_65268_65274_NPETest
{
@Test
public void testFuzz65268() throws Exception {
final IonFactory factory =
IonFactory.builderForTextualWriters().build();
try (InputStream in = getClass().getResourceAsStream("/data/fuzz-65268.ion")) {
try (JsonParser p = factory.createParser(in)) {
p.nextToken();
p.getText();
p.nextTextValue();
p.getNumberType();
}
fail("Should not pass (invalid content)");
} catch (StreamReadException e) {
assertThat(e.getMessage(), Matchers.containsString("not integer"));
}
}

@Test
public void testFuzz65274() throws Exception {
final ObjectMapper MAPPER =
IonObjectMapper.builder(
IonFactory.builderForBinaryWriters()
.enable(IonParser.Feature.USE_NATIVE_TYPE_ID)
.build())
.build();

try (InputStream in = getClass().getResourceAsStream("/data/fuzz-65274.ion")) {
byte[] invalid = new byte[in.available()];
new DataInputStream(in).readFully(invalid);
try (JsonParser p = MAPPER.getFactory().createParser(new ByteArrayInputStream(invalid))) {
MAPPER.readTree(p);
}
fail("Should not pass (invalid content)");
} catch (StreamReadException e) {
assertThat(e.getMessage(), Matchers.containsString("not integer"));
}
}
}
3 changes: 3 additions & 0 deletions ion/src/test/resources/data/fuzz-65268.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
n

null.int����~���ttttt(�t�740���������n����66}tt
Binary file added ion/src/test/resources/data/fuzz-65274.ion
Binary file not shown.