Skip to content

Commit 48149b6

Browse files
authored
Fix #599: handle skipping of CBOR string refs (#627)
1 parent 5446541 commit 48149b6

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,6 +3414,25 @@ 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+
// The finish methods will determine if the value should be added to the
3422+
// reference table based on shouldReferenceString().
3423+
if (!_stringRefs.empty()) {
3424+
if (type == CBORConstants.MAJOR_TYPE_TEXT) {
3425+
// Need to actually read the text (which may add to stringRefs)
3426+
_finishTextToken(_typeByte);
3427+
} else {
3428+
// For bytes: decode length then read (which may add to stringRefs)
3429+
int len = _decodeExplicitLength(_typeByte & 0x1F);
3430+
_finishBytes(len);
3431+
}
3432+
return;
3433+
}
3434+
3435+
// Standard skip logic when not in stringref namespace
34173436
final int lowBits = _typeByte & 0x1F;
34183437
if (lowBits <= 23) {
34193438
if (lowBits > 0) {
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)