msgpack parser failed to parse null as Map key
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 50.6k
- Forks
- 7.5k
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 58
Description
What is the issue you have?
I'm trying to parse msgpack data like:
{
null: 1
}
which serializes as 81 C0 01. But nlohmann::json::from_msgpack failed to parse it with
[json.exception.parse_error.113] parse error at byte 2: syntax error while parsing MessagePack string: expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0xC0
Please describe the steps to reproduce the issue.
↓
Can you provide a small but working code example?
#include <nlohmann/json.hpp>
int main() {
const uint8_t src[] = {0x81, 0xC0, 0x01};
nlohmann::json j = nlohmann::json::from_msgpack(src);
}
What is the expected behavior?
From the msgpack specs it doesn't restricts which value could be used on Map keys
And what is the actual behavior instead?
The specs above says
applications may remove Binary type, restrict keys of map objects to be String type, and put some restrictions to make the semantics compatible with JSON
So maybe it could be serialized to
{
"null": 1
}
like other implementation does
Which compiler and operating system are you using?
- Compiler: MSVC 19.30.30705
- Operating system: Windows 11 22000.527
Also reproduced on gcc11
Which version of the library did you use?
- latest release version 3.10.5
- other release - please state the version: 3.10.4
- the
developbranch
If you experience a compilation error: can you compile and run the unit tests?
- yes
- no - please copy/paste the error message below
- N/A
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 at the nlohmann::json::from_msgpack entry point and reproduce the issue with the byte sequence 81 C0 01 from the report. Clarify whether null map keys should be accepted or converted for JSON compatibility, then add coverage for the agreed behavior and run the relevant unit tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100