-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Crash when passing nearly-empty document #301
Comments
Were you able to build and run the unit tests? |
I can't confirm this on neither the Debian package nor the current HEAD (or 1.0-beta).
|
According to the C/C++ standards, calling `memcpy(NULL, NULL, 0)` is undefined behaviour. Recent GCC versions may rely on this by optimizing NULL pointer checks more aggressively, see [1]. This patch tries to avoid calling std::memcpy with zero elements. As a side effect, explicitly return NULL when requesting an empty block from MemoryPoolAllocator::Malloc. This may be related to Tencent#301. [1] https://gcc.gnu.org/gcc-4.9/porting_to.html
I've pushed a potential fix to my |
First of all thank you for your quick replies. TL;DR: patch fixes issues, but program still segfaults when trying a "real" JSON file. @miloyip I'm afraid unit tests don't build due to (many!) linker errors. The debian package doesn't ship with them, so unless I find the time to investigate this issue I'm afraid we'd have to do without unit test results. However, there is a new issue when testing a bigger file. See the following backtrace:
Valgrind confirms this segfault is a nullptr-exception:
Is there anything else I can provide to help understand this issue better? |
The second report seems to be similar to #200. It may be caused by a failing allocation within the Maybe you need to use the |
I shall look into using the CrtAllocator tomorrow (CEST) if it doesn't already, but to answer your question: The ARM platform is running a standard, albeit slim, Debian installation with an upstream Linux kernel 4.0rc4 or rc5. To clarify: there is no Android on this system, just Linux. |
I try to analysis the provided core dump.
If you can able to And the empty JSON object
|
I can confirm that in my test program, the new operator returns 0. I don't completely graps what goes wrong though, when executing the following code-snippet between creation of the object and calling the parse method: rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
printf( "allocator:::%p\n", &allocator ); I get
The test program you wrote executes fine, which points in the direction of... a compiler issue? |
As mentioned above, the symptoms are exactly the same as in #200. |
In #200, the reporter solved the issue by Apart from @pah 's pull request about #define RAPIDJSON_ALIGN(x) ((x + 3u) & ~3u) // 4
#define RAPIDJSON_ALIGN(x) ((x + 7u) & ~7u) // 8
#define RAPIDJSON_ALIGN(x) ((x + 15u) & ~15u) // 16 Try to define this before including any rapidjson headers. BTW, this is just a guess. Another thing that may try, is to redefine new and delete. This can be done by macro |
I just found out this issue may be related. Redefining |
According to the C/C++ standards, calling `memcpy(NULL, NULL, 0)` is undefined behaviour. Recent GCC versions may rely on this by optimizing NULL pointer checks more aggressively, see [1]. This patch tries to avoid calling std::memcpy with zero elements. As a side effect, explicitly return NULL when requesting an empty block from MemoryPoolAllocator::Malloc. This may be related to Tencent#301. [1] https://gcc.gnu.org/gcc-4.9/porting_to.html
According to the C/C++ standards, calling `memcpy(NULL, NULL, 0)` is undefined behaviour. Recent GCC versions may rely on this by optimizing NULL pointer checks more aggressively, see [1]. This patch tries to avoid calling std::memcpy with zero elements. As a side effect, explicitly return NULL when requesting an empty block from MemoryPoolAllocator::Malloc. This may be related to Tencent#301. [1] https://gcc.gnu.org/gcc-4.9/porting_to.html
Alignment to 4-bytes should be sufficient on ARMv7; the architecture does not specify stricter alignment requirements. Using CrtAllocator does solve the issues, pointing in the direction of the MemoryPoolAllocator. Either way, I hope this feedback is sufficient to help you get rapidjson running on ARM! Thanks for your time and effort to help me debug. |
The I am still interested to solve the issue with Have you tried changing the alignment settings as above? Hopefully if you have time, you may help us to discover the real reason of failing. Thank you. |
Keep a note here before closing. This issue is not fully resolved. |
I was also getting segfault when running my program after compiling with-DCMAKE_BUILD_TYPE=Release, for an ARMv7-A Cortex A9 with GCC 4.9.2-10. However, would like to understand the root cause and get the proper solution. if some one gets it let us know as well. |
I am not sure if this uses the same configuration as #758, but you may try if that workaround works. |
RapidJSON (debian, 0.12~git20141031-1) seems to crash when I pass it as a string the simple document "{ }". Expected is either a graceful failure in
hasParseError()
or areturn false
on subsequenthasMember()
requests. Instead, the following occurs:Although I hardly know the code, I suspect this might have something to do with
malloc()
being called with size 0. But I'll leave that bit to the experts!Could you look into this please?
The text was updated successfully, but these errors were encountered: