-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Unhandled exception in test-cbor.exe Stack overflow when debugging project with Visual Studio 2019 16.7.7 compiled with c++17 or c++latest #2598
Comments
Maybe related: #1685 I cannot reproduce this issue in the CI. We also have OSS Fuzz running and there has not been a stack overflow reported in a long time. I have no idea what to make out of this issue. |
Do you have a call stack showing line numbers of at least a full iteration of the infinite recursion? |
Yes, sure, here is the modified call stack, githubs comment box can only have 65536 chars, but the full call stack is 660090 chars:
|
The file that is read is: |
What file is being passed to If it is being passed |
This does sound like the issue that @nlohmann referenced that was solved by increasing the stack size from the default 1MB to 8MB. #1685 (comment) |
No, sorry I only looked for filename in unit-cbor.cpp and in line 1917 I found: std::string filename = TEST_DATA_DIRECTORY "/json_testsuite/sample.json"; But a few lines later (1924) there is a |
I solved the problem temporary by increasing the Stack Reserve Size.
This increases the stack size to 4MB and the The problems are the recursive function calls, when the test data are increased the test may fail again, because then 4MB is not enough. The stack is finite and recursion uses the stack, so there is a fundamental limit on the number of calls that can be made. |
The problem is conceptual, and I would be happy about PRs that propose a non-recursive implementation. |
Did you try it in a release build? I imagine the stack usage is a lot less there due to inlining and other optimizations. If that's the case, I don't see this as a significant issue unless it's normal to have this level of nesting in production usage and the issue happening in release builds. |
Yes this seems to be the same problem, stack size too small. |
Yes, I tried and in Release there seems to be no problem with this test file. |
Here is another solution so that the stack size can remain default: if (len==0) return sax->end_object();
auto key = std::make_unique<string_t>(); and replace |
That replaces a stack allocation of a |
I'd rather not go for such optimizations at this point. I refactored the JSON parser to work without stack recursion a while ago, and I think the same approach can be tried for the binary formats. |
Thought it was a special json string, did not see that it is a |
I think the |
In the file json.hpp in handle_value(Value&& v) an
Unhandled exception at 0x00007FF6D51C2CB8 in test-cbor.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000004760A69FF8).
is thrown when debugging the test-cbor project in Visual Studio 2019 16.7.7 compiled with /std:c++17 or with /c++latest
This occures, because of recursive function calls: from_cbor, sax_parse, parse_cbor_internal, get_cbor_object, parse_cbor_internal, ...
Please describe the steps to reproduce the issue.
shell cd json-3.9.1
mkdir build
cd build
cmake .. -DJSON_BuildTests=On -D JSON_Install:BOOL=OFF -D JSON_ImplicitConversions:BOOL=OFF -DCMAKE_CXX_FLAGS="/std:c++17"
cpp test -d json_test_data ||
withcpp if not exist json_test_data
What is the expected behavior?
No stack overflow
And what is the actual behavior instead?
Stack overflow
Which compiler and operating system are you using?
Which version of the library did you use?
The text was updated successfully, but these errors were encountered: