Skip to content

Commit 69a602d

Browse files
committed
Fix #599: handle skipping of CBOR string refs
1 parent 5446541 commit 69a602d

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORParser.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,6 +3414,50 @@ protected void _skipIncomplete() throws IOException
34143414
&& type != CBORConstants.MAJOR_TYPE_BYTES) {
34153415
_throwInternal();
34163416
}
3417+
3418+
// [dataformats-binary#599]: If we are in a stringref namespace, we need to
3419+
// actually read and store the string/bytes value instead of just skipping it,
3420+
// so that later string references can find it.
3421+
if (!_stringRefs.empty()) {
3422+
final int lowBits = _typeByte & 0x1F;
3423+
final int len = _decodeExplicitLength(lowBits);
3424+
3425+
if (type == CBORConstants.MAJOR_TYPE_TEXT) {
3426+
// For text, need to read the string to potentially store as reference
3427+
if (len >= 0) {
3428+
// Non-chunked text
3429+
if (shouldReferenceString(_stringRefs.peek().stringRefs.size(), len)) {
3430+
// Need to actually read and store the string
3431+
String str = _finishTextToken(_typeByte);
3432+
// _finishTextToken already handles adding to stringRefs
3433+
return;
3434+
}
3435+
// No need to store, can skip
3436+
} else {
3437+
// Chunked text - must read to potentially store
3438+
// Note: chunked strings may still need to be stored if large enough
3439+
String str = _finishTextToken(_typeByte);
3440+
return;
3441+
}
3442+
} else {
3443+
// For bytes, similar logic
3444+
if (len >= 0) {
3445+
if (shouldReferenceString(_stringRefs.peek().stringRefs.size(), len)) {
3446+
// Need to actually read and store the bytes
3447+
byte[] b = _finishBytes(len);
3448+
// _finishBytes already handles adding to stringRefs
3449+
return;
3450+
}
3451+
// No need to store, can skip
3452+
} else {
3453+
// Chunked bytes
3454+
byte[] b = _finishChunkedBytes();
3455+
return;
3456+
}
3457+
}
3458+
}
3459+
3460+
// Standard skip logic when not in stringref namespace
34173461
final int lowBits = _typeByte & 0x1F;
34183462
if (lowBits <= 23) {
34193463
if (lowBits > 0) {

cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/tofix/StringRef599Test.java renamed to cbor/src/test/java/com/fasterxml/jackson/dataformat/cbor/StringRef599Test.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
package com.fasterxml.jackson.dataformat.cbor.tofix;
1+
package com.fasterxml.jackson.dataformat.cbor;
22

33
import java.util.Arrays;
44

55
import com.fasterxml.jackson.core.JsonToken;
66
import com.fasterxml.jackson.databind.ObjectMapper;
77

8-
import com.fasterxml.jackson.dataformat.cbor.*;
9-
import com.fasterxml.jackson.dataformat.cbor.testutil.failure.JacksonTestFailureExpected;
10-
118
import static org.junit.jupiter.api.Assertions.assertEquals;
129

1310
import org.junit.jupiter.api.Test;
@@ -27,7 +24,6 @@ public void testDupsNoStringRef() throws Exception
2724
}
2825

2926
// [dataformats-binary#599]
30-
@JacksonTestFailureExpected
3127
@Test
3228
public void testDupsWithStringRef() throws Exception
3329
{

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,7 @@ Vincent Eigenberger (@beseder1)
422422
* Contributed fix for #601: Jackson subtype Avro schema unions are non-deterministic
423423
and therefore incompatible with each other
424424
(2.20.1)
425+
426+
Yohei Kishimoto (@morokosi)
427+
* Reported #599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties
428+
(2.21.0)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Active maintainers:
1616

1717
2.21.0 (not yet released)
1818

19+
#599: (cbor) Unable to deserialize stringref-enabled CBOR with ignored properties
20+
(reported by Yohei K)
1921
#623: (ion) Upgrade `ion-java` dep to 1.11.11 (from 1.11.10)
2022
(requested by @Shaurya0108)
2123

0 commit comments

Comments
 (0)