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

string value with null character causes infinite loop #2093

Closed
georgios-v opened this issue May 7, 2020 · 4 comments
Closed

string value with null character causes infinite loop #2093

georgios-v opened this issue May 7, 2020 · 4 comments
Labels
kind: bug state: needs more info the author of the issue needs to provide more details

Comments

@georgios-v
Copy link

  • What is the issue you have?
    I receive a json which contains a null character within a string value. while traversing this json document, calling either is_string(), is_primitive(), or is_structured() on it causes an infinite loop
    this null character either exists in the original string, or is added by the parser

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?
    call https://www.instagram.com/bradpittofflcial/?__a=1
    parse the returned json document.
    traverse to graphql/user/biography
    call is_primitive() on it

  • What is the expected behavior?
    return boolean true

  • And what is the actual behavior instead?
    doesn't terminate

  • Which compiler and operating system are you using? Is it a supported compiler?
    linux, gcc-9.3

  • Did you use a released version of the library or the version from the develop branch?
    releashed

  • If you experience a compilation error: can you compile and run the unit tests?
    yes

@nlohmann
Copy link
Owner

nlohmann commented May 7, 2020

I cannot reproduce this:

#include <iostream>
#include <fstream>
#include "json.hpp"

using json = nlohmann::json;

int main()
{
    std::ifstream f("/Users/niels/null.json");
    auto j = json::parse(f);
    std::cout << j["graphql"]["user"]["biography"] << std::endl;
    std::cout << j["graphql"]["user"]["biography"].is_primitive() << std::endl;
    std::cout << j["graphql"]["user"]["biography"].is_string() << std::endl;
    std::cout << j["graphql"]["user"]["biography"].is_structured() << std::endl;
}

Output:

"“By nature, I keep moving man. My theory is, be the shark. You've just got to keep moving. You can't stop.”\n🔹Fan Account"
1
1
0

null.json.zip

@nlohmann
Copy link
Owner

nlohmann commented May 7, 2020

An infinite loop cannot happen, as none of the is_primitive() etc. function contain a loop.

@nlohmann
Copy link
Owner

nlohmann commented May 7, 2020

Can you please provide the code that you are running?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label May 7, 2020
@georgios-v
Copy link
Author

Hello Niels, thanks for the very quick response!

unfortunately no, I cannot share the code. Also using your sample program works for me too. The infinite loop was a [false] conjecture. This code is running inside a lambda so I have now verified that it was an exception going uncaught and a worker thread crashing without trace. I was too quick to post this issue before instrumenting properly and verifying the cause.

I have now fixed my code. Thanks!

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