Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON can't parse a simple data #4383

Closed
1 of 2 tasks
jakitliang opened this issue May 29, 2024 · 2 comments
Closed
1 of 2 tasks

JSON can't parse a simple data #4383

jakitliang opened this issue May 29, 2024 · 2 comments
Labels
kind: bug state: needs more info the author of the issue needs to provide more details

Comments

@jakitliang
Copy link

jakitliang commented May 29, 2024

Description

Example data (dump from LLDB):

(lldb) p data
(char *) $3 = 0x000001ffa6a5a5d0 "{\n\t"version": [2, 6, 0, 109],\n\t"path": "C:\\Users\\Jakit\\Documents\\data\\data1"\n}\n"

Reproduction steps

Just parse the JSON then crashing

Crash position:
截屏2024-05-29 17 55 32

截屏2024-05-29 17 57 49 截屏2024-05-29 17 58 00

Expected vs. actual results

no crashing

Minimal code example

{
	"version": [2, 6, 0, 109],
	"path": "C:\\Users\\Jakit\\Documents\\data\\data"
}

Error messages

Critical error detected c0000374

Compiler and operating system

MSVC 2019

Library version

main\origin

Validation

@jakitliang jakitliang changed the title JSON parse failed and crashing my App JSON can't parse a simple data May 29, 2024
@nlohmann
Copy link
Owner

Can you share the code with that you parse that JSON?

This works without issue:

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main()
{
    auto j = json::parse(R"({
	"version": [2, 6, 0, 109],
	"path": "C:\\Users\\Jakit\\Documents\\data\\data"
})");
    std::cout << j << std::endl;
}

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label May 29, 2024
@jakitliang
Copy link
Author

Can you share the code with that you parse that JSON?

This works without issue:

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main()
{
    auto j = json::parse(R"({
	"version": [2, 6, 0, 109],
	"path": "C:\\Users\\Jakit\\Documents\\data\\data"
})");
    std::cout << j << std::endl;
}

The JSON string was store in a file data.json.

And I had found that was my fault. I got a negative number from std::ifstream::tellg then use this number as bufferSize to create a buffer storing the JSON string.

File exists but somewhere code may not correct.

So the research result is that json::parse a dirty buffer char[1024] includes some bytes like <0x09> <0x01> would crash.

And I close this issue since I fix some my issues of the file reading and buffer caching.

Thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants