Skip to content

Commit

Permalink
Merge branch '2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 29, 2023
2 parents 91edf87 + e7ad6bb commit 471e111
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
actions: read # To read the workflow path.
id-token: write # To sign the provenance.
contents: write # To add assets to a release.
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.8.0
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.9.0
with:
base64-subjects: "${{ needs.release.outputs.hash }}"
provenance-name: "${{ needs.release.outputs.artifact_name }}.jar.intoto.jsonl"
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ a pure JSON library.
#1041: Start using AssertJ in unit tests
#1042: Allow configuring spaces before and/or after the colon in `DefaultPrettyPrinter`
(contributed by @digulla)
#1047: Add configurable limit for the maximum length of Object property names
to parse before failing
(contributed by @pjfanning)
#1048: Add configurable processing limits for JSON generator (`StreamWriteConstraints`)
(contributed by @pjfanning)
#1050: Compare `_snapshotInfo` in `Version`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void validateNameLength(int length) throws StreamConstraintsException
{
if (length > _maxNameLen) {
throw _constructException(
"Name value length (%d) exceeds the maximum allowed (%d, from %s)",
"Name length (%d) exceeds the maximum allowed (%d, from %s)",
length, _maxNameLen,
_constrainRef("getMaxNameLength"));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/tools/jackson/core/base/ParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import tools.jackson.core.*;
import tools.jackson.core.exc.InputCoercionException;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.core.exc.StreamReadException;
import tools.jackson.core.exc.WrappedIOException;
import tools.jackson.core.io.ContentReference;
Expand Down Expand Up @@ -1169,4 +1170,11 @@ protected static int[] growArrayBy(int[] arr, int more) throws IllegalArgumentEx
}
return Arrays.copyOf(arr, len);
}

// Helper method to call to expand "quad" buffer for name decoding
protected int[] _growNameDecodeBuffer(int[] arr, int more) throws StreamConstraintsException {
// the following check will fail if the array is already bigger than is allowed for names
_streamReadConstraints.validateNameLength(arr.length << 2);
return growArrayBy(arr, more);
}
}
31 changes: 14 additions & 17 deletions src/main/java/tools/jackson/core/json/ReaderBasedJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ protected final String _parseName() throws JacksonException
int ch = _inputBuffer[ptr];
if (ch < codes.length && codes[ch] != 0) {
if (ch == '"') {
int start = _inputPtr;
final int start = _inputPtr;
_inputPtr = ptr+1; // to skip the quote
return _symbols.findSymbol(_inputBuffer, start, ptr - start, hash);
}
Expand All @@ -1842,7 +1842,7 @@ protected final String _parseName() throws JacksonException

private String _parseName2(int startPtr, int hash, int endChar) throws JacksonException
{
_textBuffer.resetWithShared(_inputBuffer, startPtr, (_inputPtr - startPtr));
_textBuffer.resetWithShared(_inputBuffer, startPtr, _inputPtr - startPtr);

/* Output pointers; calls will also ensure that the buffer is
* not shared and has room for at least one more char.
Expand Down Expand Up @@ -1886,11 +1886,10 @@ private String _parseName2(int startPtr, int hash, int endChar) throws JacksonEx
}
_textBuffer.setCurrentLength(outPtr);
{
TextBuffer tb = _textBuffer;
char[] buf = tb.getTextBuffer();
int start = tb.getTextOffset();
int len = tb.size();
return _symbols.findSymbol(buf, start, len, hash);
final TextBuffer tb = _textBuffer;
final char[] buf = tb.getTextBuffer();
final int start = tb.getTextOffset();
return _symbols.findSymbol(buf, start, tb.size(), hash);
}
}

Expand Down Expand Up @@ -1940,12 +1939,12 @@ protected String _handleOddName(int i) throws JacksonException
int ch = _inputBuffer[ptr];
if (ch < maxCode) {
if (codes[ch] != 0) {
int start = _inputPtr-1; // -1 to bring back first char
final int start = _inputPtr-1; // -1 to bring back first char
_inputPtr = ptr;
return _symbols.findSymbol(_inputBuffer, start, ptr - start, hash);
}
} else if (!Character.isJavaIdentifierPart((char) ch)) {
int start = _inputPtr-1; // -1 to bring back first char
final int start = _inputPtr-1; // -1 to bring back first char
_inputPtr = ptr;
return _symbols.findSymbol(_inputBuffer, start, ptr - start, hash);
}
Expand Down Expand Up @@ -2007,7 +2006,7 @@ protected JsonToken _handleOddValue(int i) throws JacksonException
switch (i) {
case '\'':
/* Allow single quotes? Unlike with regular Strings, we'll eagerly parse
* contents; this so that there'sno need to store information on quote char used.
* contents; this so that there's no need to store information on quote char used.
* Also, no separation to fast/slow parsing; we'll just do
* one regular (~= slowish) parsing, to keep code simple
*/
Expand Down Expand Up @@ -2106,7 +2105,7 @@ protected JsonToken _handleApos() throws JacksonException

private String _handleOddName2(int startPtr, int hash, int[] codes) throws JacksonException
{
_textBuffer.resetWithShared(_inputBuffer, startPtr, (_inputPtr - startPtr));
_textBuffer.resetWithShared(_inputBuffer, startPtr, _inputPtr - startPtr);
char[] outBuf = _textBuffer.getCurrentSegment();
int outPtr = _textBuffer.getCurrentSegmentSize();
final int maxCode = codes.length;
Expand Down Expand Up @@ -2139,12 +2138,10 @@ private String _handleOddName2(int startPtr, int hash, int[] codes) throws Jacks
}
_textBuffer.setCurrentLength(outPtr);
{
TextBuffer tb = _textBuffer;
char[] buf = tb.getTextBuffer();
int start = tb.getTextOffset();
int len = tb.size();

return _symbols.findSymbol(buf, start, len, hash);
final TextBuffer tb = _textBuffer;
final char[] buf = tb.getTextBuffer();
final int start = tb.getTextOffset();
return _symbols.findSymbol(buf, start, tb.size(), hash);
}
}

Expand Down
27 changes: 14 additions & 13 deletions src/main/java/tools/jackson/core/json/UTF8StreamJsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ protected final String parseLongName(int q, final int q2, int q3) throws Jackson

// Nope, no end in sight. Need to grow quad array etc
if (qlen >= _quadBuffer.length) {
_quadBuffer = growArrayBy(_quadBuffer, qlen);
_quadBuffer = _growNameDecodeBuffer(_quadBuffer, qlen);
}
_quadBuffer[qlen++] = q;
q = i;
Expand Down Expand Up @@ -2363,7 +2363,7 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
// Ok, we'll need room for first byte right away
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2379,7 +2379,7 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
// need room for middle byte?
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2398,7 +2398,7 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int
currQuad = (currQuad << 8) | ch;
} else {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand All @@ -2414,7 +2414,7 @@ protected final String parseEscapedName(int[] quads, int qlen, int currQuad, int

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = _padLastQuad(currQuad, currQuadBytes);
}
Expand Down Expand Up @@ -2474,7 +2474,7 @@ protected String _handleOddName(int ch) throws JacksonException
currQuad = (currQuad << 8) | ch;
} else {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand All @@ -2494,7 +2494,7 @@ protected String _handleOddName(int ch) throws JacksonException

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
}
Expand Down Expand Up @@ -2548,7 +2548,7 @@ protected String _parseAposName() throws JacksonException
// Ok, we'll need room for first byte right away
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2564,7 +2564,7 @@ protected String _parseAposName() throws JacksonException
// need room for middle byte?
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2583,7 +2583,7 @@ protected String _parseAposName() throws JacksonException
currQuad = (currQuad << 8) | ch;
} else {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand All @@ -2599,7 +2599,7 @@ protected String _parseAposName() throws JacksonException

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = _padLastQuad(currQuad, currQuadBytes);
}
Expand Down Expand Up @@ -2661,7 +2661,7 @@ private final String findName(int[] quads, int qlen, int lastQuad, int lastQuadB
throws StreamReadException
{
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = _padLastQuad(lastQuad, lastQuadBytes);
String name = _symbols.findName(quads, qlen);
Expand All @@ -2684,7 +2684,8 @@ private final String addName(int[] quads, int qlen, int lastQuadBytes)
* (as well as error reporting for unescaped control chars)
*/
// 4 bytes per quad, except last one maybe less
int byteLen = (qlen << 2) - 4 + lastQuadBytes;
final int byteLen = (qlen << 2) - 4 + lastQuadBytes;
_streamReadConstraints.validateNameLength(byteLen);

/* And last one is not correctly aligned (leading zero bytes instead
* need to shift a bit, instead of trailing). Only need to shift it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ protected final String _addName(int[] quads, int qlen, int lastQuadBytes)
* (as well as error reporting for unescaped control chars)
*/
// 4 bytes per quad, except last one maybe less
int byteLen = (qlen << 2) - 4 + lastQuadBytes;
final int byteLen = (qlen << 2) - 4 + lastQuadBytes;
_streamReadConstraints.validateNameLength(byteLen);

/* And last one is not correctly aligned (leading zero bytes instead
* need to shift a bit, instead of trailing). Only need to shift it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ private final JsonToken _parseEscapedName(int qlen, int currQuad, int currQuadBy
continue;
}
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand Down Expand Up @@ -2128,7 +2128,7 @@ private final JsonToken _parseEscapedName(int qlen, int currQuad, int currQuadBy
// 7-bit ASCII. Gets pretty messy. If this happens often, may
// want to use different name canonicalization to avoid these hits.
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
if (ch > 127) {
// Ok, we'll need room for first byte right away
Expand Down Expand Up @@ -2168,7 +2168,7 @@ private final JsonToken _parseEscapedName(int qlen, int currQuad, int currQuadBy

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = _padLastQuad(currQuad, currQuadBytes);
} else if (qlen == 0) { // rare, but may happen
Expand Down Expand Up @@ -2258,7 +2258,7 @@ private JsonToken _finishUnquotedName(int qlen, int currQuad, int currQuadBytes)
currQuad = (currQuad << 8) | ch;
} else {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand All @@ -2268,7 +2268,7 @@ private JsonToken _finishUnquotedName(int qlen, int currQuad, int currQuadBytes)

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
}
Expand Down Expand Up @@ -2318,7 +2318,7 @@ private JsonToken _finishAposName(int qlen, int currQuad, int currQuadBytes)
// Ok, we'll need room for first byte right away
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2334,7 +2334,7 @@ private JsonToken _finishAposName(int qlen, int currQuad, int currQuadBytes)
// need room for middle byte?
if (currQuadBytes >= 4) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = 0;
Expand All @@ -2353,7 +2353,7 @@ private JsonToken _finishAposName(int qlen, int currQuad, int currQuadBytes)
currQuad = (currQuad << 8) | ch;
} else {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = currQuad;
currQuad = ch;
Expand All @@ -2363,7 +2363,7 @@ private JsonToken _finishAposName(int qlen, int currQuad, int currQuadBytes)

if (currQuadBytes > 0) {
if (qlen >= quads.length) {
_quadBuffer = quads = growArrayBy(quads, quads.length);
_quadBuffer = quads = _growNameDecodeBuffer(quads, quads.length);
}
quads[qlen++] = _padLastQuad(currQuad, currQuadBytes);
} else if (qlen == 0) { // rare case but possible
Expand All @@ -2385,7 +2385,7 @@ protected final JsonToken _finishPropertyWithEscape() throws JacksonException
return JsonToken.NOT_AVAILABLE;
}
if (_quadLength >= _quadBuffer.length) {
_quadBuffer = growArrayBy(_quadBuffer, 32);
_quadBuffer = _growNameDecodeBuffer(_quadBuffer, 32);
}
int currQuad = _pending32;
int currQuadBytes = _pendingBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ public String findSymbol(char[] buffer, int start, int len, int h)
return "";
}
if (!_canonicalize) { // [JACKSON-259]
_streamReadConstraints.validateNameLength(len);
return new String(buffer, start, len);
}

Expand Down Expand Up @@ -495,6 +496,7 @@ public String findSymbol(char[] buffer, int start, int len, int h)
}
}
}
_streamReadConstraints.validateNameLength(len);
return _addSymbol(buffer, start, len, h, index);
}

Expand Down
Loading

0 comments on commit 471e111

Please sign in to comment.