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

What is the maximum key length allowed? #152

Closed
CrendKing opened this issue Sep 25, 2014 · 2 comments
Closed

What is the maximum key length allowed? #152

CrendKing opened this issue Sep 25, 2014 · 2 comments
Milestone

Comments

@CrendKing
Copy link

I noticed that even in Jackson 2.4, if a JSON key is longer than 262144 bytes, ArrayIndexOutOfBoundsException is thrown from TextBuffer. Below is the stack trace:

java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at com.fasterxml.jackson.core.util.TextBuffer.expandCurrentSegment(TextBuffer.java:604)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.addName(UTF8StreamJsonParser.java:2034)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.findName(UTF8StreamJsonParser.java:1928)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.parseLongFieldName(UTF8StreamJsonParser.java:1534)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.parseMediumFieldName(UTF8StreamJsonParser.java:1502)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._parseFieldName(UTF8StreamJsonParser.java:1437)
    at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:668)
    ... <below are our code> ...

Looking at TextBuffer.expandCurrentSegment(TextBuffer.java:604), once the length of _currentSegment is increased to MAX_SEGMENT_LEN + 1 (262145) bytes, the newLen will stay at MAX_SEGMENT_LEN, which is smaller than len. Therefore System.arraycopy() will fail.

I understand it is rare to have key larger than 262144 bytes, but it would be nice if

  • Jackson explicitly throw exception stating that key is too long.
  • Document that the maximum key length is 262144 bytes.

OR

  • Update TextBuffer to support super long key.

Thanks!

@cowtowncoder
Copy link
Member

No such limit is intended, so this sounds like a bug. Will fix it; no reason not to support whatever fits in memory. Note that maximum segment is not directly relevant to maximum key length -- the point of segments is not to require a single contiguous array, or intermediate copies.

@cowtowncoder
Copy link
Member

Actually, looking at code, expansion is used for case of property names (where names are kept in a single buffer) -- not so for text values, but here it is done. Regardless, something to fix.

cowtowncoder added a commit that referenced this issue Sep 25, 2014
@cowtowncoder cowtowncoder added this to the 2.4.3 milestone Sep 25, 2014
cowtowncoder added a commit that referenced this issue Sep 25, 2014
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