Skip to content

Binary formats invalid encoding for <discarded> values in arrays and objects #4714

@nebkat

Description

@nebkat

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: {i�bari�bazi�i�fooi�}
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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions