Skip to content

Error when roundtripping BJData #3519

Closed

Description

@nlohmann

Description

Given the following BJData input

00000000: 5b24 4d23 5b49 0020 4d00 0000 0000 0020  [$M#[I. M...... 
00000010: ff5d                                     .]

the library can successfully parse it to

{
    "_ArrayData_": [],
    "_ArraySize_": [
        8192,
        -63050394783186944
    ],
    "_ArrayType_": "uint64"
}

However, when then serializing this JSON as BJData, the following exception is raised:

[json.exception.parse_error.113] parse error at byte 17: syntax error while parsing BJData size: count in an optimized container must be positive

The error was found by OSS-Fuzz, and is unrelated to the latest fixes.

Reproduction steps

int main() {
    auto vec = readFile("clusterfuzz-testcase-minimized-parse_bjdata_fuzzer-5159110460440576.bjdata");

    auto j = json::from_bjdata(vec);
    std::vector<uint8_t> vec2 = json::to_bjdata(j, false, false);

    json::from_bjdata(vec2);
}

Expected vs. actual results

  • Expected: Either reject the original input or (also) accept the created byte vector.
  • Actual: Accepting the input, but rejecting the byte vector.

I would also be fine with adding a note to https://json.nlohmann.me/features/binary_formats/bjdata/, but then we also need to adjust https://github.com/nlohmann/json/blob/develop/tests/src/fuzzer-parse_bjdata.cpp#L65

Minimal code example

See above.

Error messages

[json.exception.parse_error.113] parse error at byte 17: syntax error while parsing BJData size: count in an optimized container must be positive

Compiler and operating system

OSS-Fuzz

Library version

develop

Validation

Activity

  1. nlohmann commented on Jun 6, 2022

    @nlohmann
    OwnerAuthor
  2. added a commit that references this issue on Jun 6, 2022
    bccd7ae
  3. self-assigned this
    on Jun 9, 2022
  4. added this to the Release 3.11.0 milestone on Jun 9, 2022
  5. added a commit that references this issue on Jun 9, 2022
    48a102c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址