Skip to content

Commit de8c970

Browse files
authored
Catch and handle from exceptions from IonReader (FasterXML#467)
1 parent fd66c23 commit de8c970

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,9 @@ public String getText() throws IOException
291291
// Some special cases here:
292292
case VALUE_EMBEDDED_OBJECT:
293293
if (_reader.getType() == IonType.TIMESTAMP) {
294-
try {
295-
Timestamp ts = _reader.timestampValue();
296-
if (ts != null) {
297-
return ts.toString();
298-
}
299-
} catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
300-
// 07-Jan-2024, tatu: OSS-Fuzz#65628 points to AIOOBE:
301-
return _reportCorruptContent(e);
294+
Timestamp ts = _timestampFromIonReader();
295+
if (ts != null) {
296+
return ts.toString();
302297
}
303298
}
304299
// How about CLOB?
@@ -549,7 +544,7 @@ public byte[] getBinaryValue(Base64Variant arg0) throws IOException
549544
switch (_reader.getType()) {
550545
case BLOB:
551546
case CLOB: // looks like CLOBs are much like BLOBs...
552-
return _reader.newBytes();
547+
return _bytesFromIonReader();
553548
default:
554549
}
555550
}
@@ -577,30 +572,43 @@ public Object getEmbeddedObject() throws IOException {
577572
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
578573
switch (_reader.getType()) {
579574
case TIMESTAMP:
580-
try {
581-
return _reader.timestampValue();
582-
} catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
583-
return _reportCorruptContent(e);
584-
} catch (IllegalArgumentException e) {
585-
throw _constructError(String.format(
586-
"Invalid embedded TIMESTAMP value, problem: %s", e.getMessage()),
587-
e);
588-
}
575+
return _timestampFromIonReader();
589576
case BLOB:
590577
case CLOB:
591-
try {
592-
return _reader.newBytes();
593-
} catch (NullPointerException e) {
594-
// 02-Jan-2024, tatu: OSS-Fuzz#65479 points to NPE ^^^
595-
return _reportCorruptContent(e);
596-
}
578+
return _bytesFromIonReader();
597579
// What about CLOB?
598580
default:
599581
}
600582
}
601583
return getIonValue();
602584
}
603585

586+
// @since 2.17
587+
private byte[] _bytesFromIonReader() throws IOException {
588+
try {
589+
return _reader.newBytes();
590+
} catch (NullPointerException
591+
// 02-Jan-2024, tatu: OSS-Fuzz#65479 points to NPE ^^^
592+
| NegativeArraySizeException e) {
593+
// 23-Jan-2024, tatu: OSS-Fuzz#66077 points to NASE ^^^
594+
return _reportCorruptContent(e);
595+
}
596+
}
597+
598+
// @since 2.17
599+
private Timestamp _timestampFromIonReader() throws IOException {
600+
try {
601+
return _reader.timestampValue();
602+
} catch (ArrayIndexOutOfBoundsException | NullPointerException e) {
603+
// 07-Jan-2024, tatu: OSS-Fuzz#65628 points to AIOOBE:
604+
return _reportCorruptContent(e);
605+
} catch (IllegalArgumentException e) {
606+
throw _constructError(String.format(
607+
"Invalid embedded TIMESTAMP value, problem: %s", e.getMessage()),
608+
e);
609+
}
610+
}
611+
604612
/*
605613
/**********************************************************
606614
/* Public API, Native Ids (type, object)

0 commit comments

Comments
 (0)