0

My program to load json file gives SEGV intermittently with following signature.

034613:/../lib/libtcmalloc.so.4(operator new(unsigned long) 0xc9)[0x7f493d215f99]
/lib/libjsoncpp.so(Json::Value::Value(Json::Value const&) 0xcc)[0x7f493ffa7f3a]
lib/libjsoncpp.so(Json::Value::operator=(Json::Value const&) 0x23)[0x7f493ffa81fd]lib/libjsoncpp.so
(Json::Reader::readObject(Json::Reader::Token&) 0x60)
[0x7f493ffa1cae]lib/libjsoncpp.so(Json::Reader::readValue() 0x103)[0x7f493ffa10f7]\n", 

and the code which results in this error is

ifstream config_stream(config_file);
string config_data((std::istreambuf_iterator<char>(config_stream)),
                    std::istreambuf_iterator<char>());
Json::Reader reader(Json::Features::all());
Json::Value json_parsed_data;
CHECK(reader.parse(config_data, json_parsed_data))

Potential reason from related artickles i checked was this could happen if the json file is too large and has a lot of nesting, but that's not my case.

My json file has 1 level of nesting and about 100 entries, overall file is not more than 400 lines, Anyone faced similar issue while reading from json files in c++ ?

Denis Sheremet
  • 2,453
  • 2
  • 18
  • 34
  • If your input is valid json and it does not contain any sensible data, it would probably be a good idea to file a bug to jsoncpp devs with that file – Denis Sheremet Feb 06 '20 at 11:39
  • @DenisSheremet yes json input is valid, Also its not happening consistently, it happens intermittently – Uddhav Mishra Feb 06 '20 at 11:48
  • 2
    This may actually be a symbol of heap corruption elsewhere, as the crash is inside tcmalloc. Can you reproduce this with only the code you showed ? – Botje Feb 06 '20 at 12:02
  • @Botje that could be the case, how can we confirm that its due to heap corruption – Uddhav Mishra Feb 07 '20 at 09:23
  • You can try setting the `MALLOC_CHECK_` environment variable to 1, that might already give you a clue. – Botje Feb 07 '20 at 10:53

0 Answers0