Binary formats invalid encoding for <discarded> values in arrays and objects
Open
Nobody has claimed this yet.
aspect: binary formats
kind: bug
- Dominant language
- C++
- Stars
- 50.6k
- Forks
- 7.5k
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 58
Description
Description
Binary formats (BSON, CBOR, MessagePack, UBJSON/BJData) are creating broken outputs when <discarded> values are included in arrays/objects.
Reproduction steps
https://godbolt.org/z/WEPP5WrYe
JSON array encoded: [<discarded>,<discarded>,<discarded>,1]
JSON array parsed: [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing value - invalid literal; last read: '[<'
UBJSON array encoded: [i]
UBJSON array parsed: [1]
MSGPCK array encoded: 0x 94 01
MSGPCK array parsed: [json.exception.parse_error.110] parse error at byte 3: syntax error while parsing MessagePack value: unexpected end of input
CBOR array encoded: 0x 84 01
CBOR array parsed: [json.exception.parse_error.110] parse error at byte 3: syntax error while parsing CBOR value: unexpected end of input
JSON object encoded: {"bar":<discarded>,"baz":2,"foo":1}
JSON object parsed: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - invalid literal; last read: '"bar":<'
UBJSON object encoded: {ibaribaziifooi}
UBJSON object parsed: [json.exception.parse_error.113] parse error at byte 9: syntax error while parsing UBJSON string: expected length type specification (U, i, I, l, L); last byte: 0x62
MSGPCK object encoded: 0x 83 a3 62 61 72 a3 62 61 7a 02 a3 66 6f 6f 01
MSGPCK object parsed: [json.exception.parse_error.113] parse error at byte 10: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x02
CBOR object encoded: 0x a3 63 62 61 72 63 62 61 7a 02 63 66 6f 6f 01
CBOR object parsed: [json.exception.parse_error.113] parse error at byte 10: syntax error while parsing CBOR string: expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x02
Compiler and operating system
N/A
Library version
3.11.3
Validation
- The bug also occurs if the latest version from the
developbranch is used. - I can successfully compile and run the unit tests.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Godbolt reproduction and inspect the binary-format serialization entry points for arrays and objects. Compare BSON, CBOR, MessagePack, and UBJSON/BJData behavior for discarded values, then add regression coverage showing that encoded data remains decodable and preserves the intended structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100