diff --git a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java index 370556583..b46c1cfca 100644 --- a/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java +++ b/cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java @@ -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) { @@ -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); @@ -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); @@ -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) { @@ -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; } - */ /* /********************************************************** diff --git a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java similarity index 98% rename from cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java rename to cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java index 8d88817fb..680f0d78b 100644 --- a/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/failing/SymbolTable312Test.java +++ b/cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/parse/SymbolTable312Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.dataformat.cbor.failing; +package com.fasterxml.jackson.dataformat.cbor.parse; import java.nio.charset.StandardCharsets; diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 491407d79..6a9eca605 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -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) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 750de4abf..511ed1677 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -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) diff --git a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java index 4e0da53ab..d1bca9537 100644 --- a/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java +++ b/smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileParser.java @@ -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; } @@ -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) { @@ -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); @@ -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); @@ -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) { @@ -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; + } /* /********************************************************** diff --git a/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java b/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/parse/SymbolTable312Test.java similarity index 98% rename from smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java rename to smile/src/test/java/com/fasterxml/jackson/dataformat/smile/parse/SymbolTable312Test.java index 710d76908..07f459289 100644 --- a/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/failing/SymbolTable312Test.java +++ b/smile/src/test/java/com/fasterxml/jackson/dataformat/smile/parse/SymbolTable312Test.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.dataformat.smile.failing; +package com.fasterxml.jackson.dataformat.smile.parse; import java.nio.charset.StandardCharsets;