Skip to content

Commit

Permalink
Wrap the method call with try catch block
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <[email protected]>
  • Loading branch information
arthurscchan committed Dec 27, 2023
1 parent e4a993c commit 4c47b75
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ 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
}
if (size == null) {
_reportError("Current token (%s) not integer", _currToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.fasterxml.jackson.dataformat.ion.fuzz;

import java.io.InputStream;

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;

import java.io.*;
import java.nio.file.*;

// [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 = in.readAllBytes();
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"));
}
}
}

This file was deleted.

Binary file added ion/src/test/resources/data/fuzz-65274.ion
Binary file not shown.

0 comments on commit 4c47b75

Please sign in to comment.