Skip to content

Commit

Permalink
Fixed #312 (use 0xFF for padding empty/missing bytes as its not valid…
Browse files Browse the repository at this point in the history
… UTF-8 byte)
  • Loading branch information
cowtowncoder committed Feb 26, 2022
1 parent 6e06b38 commit b082f58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
if (len < 5) {
int inPtr = _inputPtr;
final byte[] inBuf = _inputBuffer;
int q = inBuf[inPtr] & 0xFF;
int q = _padQuadForNulls(inBuf[inPtr]);
if (len > 1) {
q = (q << 8) + (inBuf[++inPtr] & 0xFF);
if (len > 2) {
Expand All @@ -2910,7 +2910,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
q1 = (q1 << 8) | (inBuf[inPtr++] & 0xFF);

if (len < 9) {
int q2 = (inBuf[inPtr++] & 0xFF);
int q2 = _padQuadForNulls(inBuf[inPtr++]);
int left = len - 5;
if (left > 0) {
q2 = (q2 << 8) + (inBuf[inPtr++] & 0xFF);
Expand All @@ -2932,7 +2932,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
q2 = (q2 << 8) | (inBuf[inPtr++] & 0xFF);

if (len < 13) {
int q3 = (inBuf[inPtr++] & 0xFF);
int q3 = _padQuadForNulls(inBuf[inPtr++]);
int left = len - 9;
if (left > 0) {
q3 = (q3 << 8) + (inBuf[inPtr++] & 0xFF);
Expand Down Expand Up @@ -2981,7 +2981,7 @@ private final String _findDecodedLong(int len, int q1, int q2) throws IOExceptio
} while ((len -= 4) > 3);
// and then leftovers
if (len > 0) {
int q = inBuf[inPtr] & 0xFF;
int q = _padQuadForNulls(inBuf[inPtr]);
if (len > 1) {
q = (q << 8) + (inBuf[++inPtr] & 0xFF);
if (len > 2) {
Expand Down Expand Up @@ -3012,12 +3012,9 @@ private static int[] _growArrayTo(int[] arr, int minSize) {
}

// Helper method needed to fix [dataformats-binary#312], masking of 0x00 character
// 26-Feb-2022, tatu: not yet used
/*
private final static int _padLastQuad(int q, int bytes) {
return (bytes == 4) ? q : (q | (-1 << (bytes << 3)));
private final static int _padQuadForNulls(int firstByte) {
return (firstByte & 0xFF) | 0xFFFFFF00;
}
*/

/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.cbor.failing;
package com.fasterxml.jackson.dataformat.cbor.parse;

import java.nio.charset.StandardCharsets;

Expand Down
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,8 @@ Martin Giannechini (MartinGian@github)
* Contributed fix for #295: (ion) `jackson-dataformat-ion` does not handle null.struct
deserialization correctly
(2.13.0)

David Turner (DaveCTurner@github)

* Reported #312: (cbor, smile) Short NUL-only keys incorrectly detected as duplicates
(2.14.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Modules:

#301: (cbor, smile) Missing configuration methods for format-specific
parser/generator features
#312: (cbor, smile) Short NUL-only keys incorrectly detected as duplicates
(reported by David T)

2.13.1 (19-Dec-2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ private final String _handleLongFieldName() throws IOException
if (quads >= _quadBuffer.length) {
_quadBuffer = _growArrayTo(_quadBuffer, _quadBuffer.length + 256);
}
q = _padLastQuad(q, bytes);
_quadBuffer[quads++] = q;
byteLen += bytes;
}
Expand Down Expand Up @@ -1825,7 +1826,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
if (len < 5) {
int inPtr = _inputPtr;
final byte[] inBuf = _inputBuffer;
int q = inBuf[inPtr] & 0xFF;
int q = _padQuadForNulls(inBuf[inPtr]);
if (len > 1) {
q = (q << 8) + (inBuf[++inPtr] & 0xFF);
if (len > 2) {
Expand All @@ -1849,7 +1850,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
q1 = (q1 << 8) | (inBuf[inPtr++] & 0xFF);

if (len < 9) {
int q2 = (inBuf[inPtr++] & 0xFF);
int q2 = _padQuadForNulls(inBuf[inPtr++]);
int left = len - 5;
if (left > 0) {
q2 = (q2 << 8) + (inBuf[inPtr++] & 0xFF);
Expand All @@ -1871,7 +1872,7 @@ private final String _findDecodedFromSymbols(final int len) throws IOException
q2 = (q2 << 8) | (inBuf[inPtr++] & 0xFF);

if (len < 13) {
int q3 = (inBuf[inPtr++] & 0xFF);
int q3 = _padQuadForNulls(inBuf[inPtr++]);
int left = len - 9;
if (left > 0) {
q3 = (q3 << 8) + (inBuf[inPtr++] & 0xFF);
Expand Down Expand Up @@ -1920,7 +1921,7 @@ private final String _findDecodedFixed12(int len, int q1, int q2) throws IOExcep
} while ((len -= 4) > 3);
// and then leftovers
if (len > 0) {
int q = inBuf[inPtr] & 0xFF;
int q = _padQuadForNulls(inBuf[inPtr]);
if (len > 1) {
q = (q << 8) + (inBuf[++inPtr] & 0xFF);
if (len > 2) {
Expand All @@ -1940,13 +1941,15 @@ private static int[] _growArrayTo(int[] arr, int minSize) {
return Arrays.copyOf(arr, size);
}

// Helper method needed to fix [dataformats-binary#312], masking of 0x00 character
// 26-Feb-2022, tatu: not yet used
/*
// Helper methods needed to fix [dataformats-binary#312], masking of 0x00 character

private final static int _padLastQuad(int q, int bytes) {
return (bytes == 4) ? q : (q | (-1 << (bytes << 3)));
}
*/

private final static int _padQuadForNulls(int firstByte) {
return (firstByte & 0xFF) | 0xFFFFFF00;
}

/*
/**********************************************************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.smile.failing;
package com.fasterxml.jackson.dataformat.smile.parse;

import java.nio.charset.StandardCharsets;

Expand Down

0 comments on commit b082f58

Please sign in to comment.