diff --git a/src/main/java/com/fasterxml/jackson/core/sym/ByteQuadsCanonicalizer.java b/src/main/java/com/fasterxml/jackson/core/sym/ByteQuadsCanonicalizer.java index e705ab7c18..3a3d545986 100644 --- a/src/main/java/com/fasterxml/jackson/core/sym/ByteQuadsCanonicalizer.java +++ b/src/main/java/com/fasterxml/jackson/core/sym/ByteQuadsCanonicalizer.java @@ -1114,14 +1114,19 @@ private boolean _checkNeedForRehash() { return false; } - private int _appendLongName(int[] quads, int qlen) + private int _appendLongName(final int[] quads, final int qlen) { - int start = _longNameOffset; + final int start = _longNameOffset; + final int newStart = start + qlen; + if (newStart < 0) { + throw new IllegalStateException(String.format( + "Internal error: long name offset overflow; start=%s, qlen=%s", start, qlen)); + } - // note: at this point we must already be shared. But may not have enough space - if ((start + qlen) > _hashArea.length) { + // note: at this point we must already be unshared. But may not have enough space + if (newStart > _hashArea.length) { // try to increment in reasonable chunks; at least space that we need - int toAdd = (start + qlen) - _hashArea.length; + int toAdd = newStart - _hashArea.length; // but at least 1/8 of regular hash area size or 16kB (whichever smaller) int minAdd = Math.min(4096, _hashSize); @@ -1129,7 +1134,7 @@ private int _appendLongName(int[] quads, int qlen) _hashArea = Arrays.copyOf(_hashArea, newSize); } System.arraycopy(quads, 0, _hashArea, start, qlen); - _longNameOffset += qlen; + _longNameOffset = newStart; return start; } @@ -1259,9 +1264,8 @@ private void rehash() throws StreamConstraintsException final int newSize = oldSize + oldSize; final int oldEnd = _spilloverEnd; - /* 13-Mar-2010, tatu: Let's guard against OOME that could be caused by - * large documents with unique (or mostly so) names - */ + // 13-Mar-2010, tatu: Let's guard against OOME that could be caused by + // large documents with unique (or mostly so) names if (newSize > MAX_T_SIZE) { nukeSymbols(true); return;