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

fail if int overflow in _longNameOffset #1358

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1114,22 +1114,27 @@ 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);

int newSize = _hashArea.length + Math.max(toAdd, minAdd);
_hashArea = Arrays.copyOf(_hashArea, newSize);
}
System.arraycopy(quads, 0, _hashArea, start, qlen);
_longNameOffset += qlen;
_longNameOffset = newStart;
return start;
}

Expand Down Expand Up @@ -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;
Expand Down