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

'IndexOutOfBoundsException' in UTF8JsonGenerator.writeString(Reader, len) when using a negative length #556

Closed
jake-a-ward opened this issue Aug 23, 2019 · 4 comments
Milestone

Comments

@jake-a-ward
Copy link

I encountered this using Jackson 2.9.9

The JavaDoc for JsonGenerator.writeString(Reader, len) states that passing a len < 0 will write all contents of the reader. It throws an IndexOutOfBoundsException when the buffer in UTF8JsonGenerator becomes full but is not correctly flushed because the check for a full buffer does not take into account the negative len parameter.

Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Index 8000 out of bounds for length 8000 (through reference chain: java.util.ArrayList[2]) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:394) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:365) at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:338) at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:123) at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79) at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:319) at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3905) at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3176) at jackson.bug.JacksonBugTest.main(JacksonBugTest.java:36) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131) Suppressed: java.lang.IndexOutOfBoundsException: Range [0, 0 + 8001) out of bounds for length 8000 at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromIndexSize(Preconditions.java:82) at java.base/jdk.internal.util.Preconditions.checkFromIndexSize(Preconditions.java:343) at java.base/java.util.Objects.checkFromIndexSize(Objects.java:425) at java.base/java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:129) at com.fasterxml.jackson.core.json.UTF8JsonGenerator._flushBuffer(UTF8JsonGenerator.java:2085) at com.fasterxml.jackson.core.json.UTF8JsonGenerator.close(UTF8JsonGenerator.java:1127) at com.fasterxml.jackson.databind.util.ClassUtil.closeOnFailAndThrowAsIOE(ClassUtil.java:488) at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3907) ... 7 more Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 8000 out of bounds for length 8000 at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeString(UTF8JsonGenerator.java:503) at jackson.bug.JacksonBugTest$ThingSerializer.serialize(JacksonBugTest.java:45) at jackson.bug.JacksonBugTest$ThingSerializer.serialize(JacksonBugTest.java:40) at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119) ... 12 more

@jake-a-ward
Copy link
Author

Here is the code that I used to recreate the problem
JacksonBugTest.zip

@cowtowncoder
Copy link
Member

Thank you for reporting this problem! I hope to have time to check this out over the weekend.

@cowtowncoder cowtowncoder modified the milestones: 2.9.0, 2.9.10 Aug 27, 2019
@cowtowncoder
Copy link
Member

Whoa. That was pretty obvious bug in contributed code. I didn't do very good code review originally...

Thank you for reporting this: fixed for 2.10.0.pr2 but backported in 2.9 too for eventual 2.9.10.

@jake-a-ward
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants