open-source-parsers / open-source-parsers/jsoncpp

Long String Not Supported

Open
#1,329 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
8.9k
Forks
2.7k
Avg merge
31m
Merged PRs (30d)
1

Description

Describe the bug
When reading a json file, if the length of a string is larger than 0xffffffff(i.e. 32bit), it cannot be fully loaded.

To Reproduce
Steps to reproduce the behavior:

  1. Construct a json file, containing a string, the length of which is larger than 0xffffffff, e.g. 0x8abcdefff. To ensure that this file is as we imagined and legal, you can use functions like json.dump in python3.
  2. Load that file in cpp(compile in x64, so that type size_t is 64bit) using jsoncpp into a variable Json::Value root, try get that string unsigned long long len = strlen(root['str'].asCString()).
  3. Print that length using "%llu": printf("length = %llu", len)
  4. You will find that the printed value is exactly the low 32bit of length of the original string created using python3.

Expected behavior
Make everything support 64bit length strings in legal json files.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.3
  • libjsoncpp-dev 1.7.4-3
  • gcc 7.5.0

Additional context
I met this problem when trying to process some super long strings.
I checked my programming, compiling settings, and everything to do with data type and bit length(mostly using unsigned long long instead of int or unsigned).
At last, in function asCString and decodePrefixedString in json_value.cpp, I found that variables describing lengths in these functions are simply unsigned, which can make everything 32bit.
I got a super large RAM for super long strings.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in json_value.cpp at asCString and decodePrefixedString, where the issue identifies unsigned length variables, and inspect how string lengths are represented during JSON loading. Reproduce with a legal JSON string exceeding 32-bit length on a 64-bit build; done means the full string loads and its reported length is not truncated.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.