Wrap unexpected RuntimeException from parsers as StreamReadException in _readTreeAndClose#5882
Wrap unexpected RuntimeException from parsers as StreamReadException in _readTreeAndClose#5882
Conversation
…adTreeAndClose (#5881) Agent-Logs-Url: https://github.com/FasterXML/jackson-databind/sessions/f30927f0-861f-432d-bb32-36940bfe32fc Co-authored-by: pjfanning <11783444+pjfanning@users.noreply.github.com>
Catch JacksonException separately to handle it directly.
|
Relates to FasterXML/jackson-dataformats-text#648. The problem in 648 is that we could update the code in any of 3 libs to avoid the ArrayIndexOutOfBoundsException. jackson-core, jackson-databind, jackson-dataformat-csv. Our docs suggest that we only throw JacksonExceptions, so there is an argument for catching other RuntimeExceptions in key places and wrapping them in JacksonExceptions. |
|
I don't think this is a good idea. FasterXML/jackson-dataformats-text#648 was a clear simple regression caught by Fuzzer, and if we had caught, re-thrown exception, Fuzzer would not have noticed anything. |
Some format backends (e.g., jackson-dataformats-text CSV) can throw unchecked
RuntimeExceptionon corrupt input rather thanJacksonException, violating the API contract ofreadTree. The specific trigger:CsvDecoderpasses totalspaceCount(instead of per-segment_currentSize) asoutPtrto_nextUnquotedStringafterTextBuffer.resetWithCopyexpands into a new segment — causingfinishAndReturnto be called withlastSegmentEnd > _currentSegment.length, which propagates asIndexOutOfBoundsExceptionout ofTextBuffer.contentsAsString.Changes
ObjectMapper._readTreeAndClose: Wrap thereadRootValuecall in atry/catch (RuntimeException)that re-throws asStreamReadException("Unexpected character (corrupt input): ..."), preserving the original exception as cause. This keeps thethrows JacksonExceptioncontract and surfaces a meaningful error instead of a raw buffer exception.