{"action":"created","issue":{"url":"https://api.github.com/repos/byzhang/rapidjson/issues/11","labels_url":"https://api.github.com/repos/byzhang/rapidjson/issues/11/labels{/name}","comments_url":"https://api.github.com/repos/byzhang/rapidjson/issues/11/comments","events_url":"https://api.github.com/repos/byzhang/rapidjson/issues/11/events","html_url":"https://github.com/byzhang/rapidjson/issues/11","id":59729634,"number":11,"title":"Segmentation fault - document.h line 618","user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/auto-migrated","name":"auto-migrated","color":"ededed"},{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/Priority-High","name":"Priority-High","color":"ededed"},{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/Type-Defect","name":"Type-Defect","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-03-04T00:12:47Z","updated_at":"2015-03-04T00:12:48Z","closed_at":"2015-03-04T00:12:47Z","body":"```\nif (name[member->name.data_.s.length] == '\\0' && \nmemcmp(member->name.data_.s.str, name, member->name.data_.s.length * \nsizeof(Ch)) == 0)\n\t\t\t\treturn member;\n}\n\nThis code in document.h line 618 generate segmentation fault on the ARM\narchitecture.\n\nProblem in the member->name.data_.s.str but I don't know why.\nCString at member->name.data_.s.str exist.\n```\n\nOriginal issue reported on code.google.com by `archj...@gmail.com` on 31 Jan 2012 at 2:09"},"comment":{"url":"https://api.github.com/repos/byzhang/rapidjson/issues/comments/77069421","html_url":"https://github.com/byzhang/rapidjson/issues/11#issuecomment-77069421","issue_url":"https://api.github.com/repos/byzhang/rapidjson/issues/11","id":77069421,"user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"created_at":"2015-03-04T00:12:48Z","updated_at":"2015-03-04T00:12:48Z","body":"```\nHi Milo,\n\nAgain, a great library.  I really like it.\n\nRegarding issue 11, I am still having problems.  It still segfaults, owing\napparently to assumptions about alignment of derived class GenericDocument\nwith respect to its base class, GenericValue.\n\nStack trace:\n\nrapidjson (1) [BlackBerry Tablet OS Postmortem Debugging]\n    QNX GDB Debugger (12-02-21 10:25 AM) (Suspended)\n        Thread [1] (Suspended)\n            5\nrapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>::Realloc()\n/home/johodgson/rapidjson/include/rapidjson/allocators.h:171 0x0010504c\n            4 rapidjson::GenericValue<rapidjson::UTF8<char>,\nrapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::Reserve()\n/home/johodgson/rapidjson/include/rapidjson/document.h:377 0x00104e58\n            3 rapidjson::GenericValue<rapidjson::UTF8<char>,\nrapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::PushBack()\n/home/johodgson/rapidjson/include/rapidjson/document.h:393 0x00103a20\n            2 rapidjson::GenericValue<rapidjson::UTF8<char>,\nrapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::PushBack<int>()\n/home/johodgson/rapidjson/include/rapidjson/document.h:401 0x00102a64\n            1 main()\n/home/johodgson/rapidjson/example/tutorial/tutorial.cpp:88 0x001016cc\n    /opt/bbndk-2.0.0/host/linux/x86/usr/bin/ntoarm-gdb (12-02-21 10:25\nAM)\n    <terminated, exit value:\n0>/home/johodgson/rapidjson/Device-Debug/rapidjson (12-02-21 10:25 AM)\n\n\nVariables:\n\nthis    0x00000000\noriginalPtr    0x0019042c\noriginalSize    96\nnewSize    192\n__func__    0x0010b7a4\nnewBuffer    0x001905c4\n\n\nAllocator (this) is NULL, because it gets clobbered with a memcpy using\nsizeof(GenericValue) (=24 bytes).  I checked it out using View Memory in my\nQNX Momentics IDE.  Layout of derived class GenericDocument object is\nimmediately following GenericValue (starting at byte 20), without the extra\nfour bytes of padding at the end of GenericValue.  The compiler puts in the\nextra padding (I don't know why), which is what brings it out to the sizeof\n24 bytes, but the compiler does not use this padding when laying out the\nderived class.\n\nMy compiler is QCC:\n\nqcc -o example/tutorial/tutorial.o ../example/tutorial/tutorial.cpp\n-V4.4.2,gcc_ntoarmv7le_cpp -w1\n-I/opt/bbndk-2.0.0/target/qnx6/../target-override/usr/include\n-I/home/johodgson/rapidjson/include\n-I/home/johodgson/rapidjson/thirdparty/gtest/include -D_FORTIFY_SOURCE=2 -c\n-g -fstack-protector-all\nqcc -o rapidjson example/tutorial/tutorial.o -V4.4.2,gcc_ntoarmv7le_cpp -w1\n-lang-c++ -g -Wl,-z,relro -Wl,-z,now\n-L/opt/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/lib\n-L/opt/bbndk-2.0.0/target/qnx6/../target-override/armle-v7/usr/lib\n\nThis change at the bottom of document.h fixes it for me, because it simply\nmoves GenericDocument data farther down, out of the range of clobbering.\n\n     static const size_t kDefaultStackCapacity = 1024;\n+    char padding_[4];\n     internal::Stack<Allocator> stack_;\n     const char* parseError_;\n     size_t errorOffset_;\n\nI think that this is a safe change for 32-bit architectures, but may not\nwork on a 64-bit architecture (may need to add more padding, e.g., 8 bytes).\n\nI'm working on an ARM v7 on RIM PlayBook, which is 32-bit.  The new ARM v8\nwill be 64-bit, so stuff compiled as 64-bit may not work.\n\nYour library is a really nice template approach.  The inheritance\nGenericValue <- GenericDocument may be out-of-character.  Maybe there is a\nway to move out the document-building code and avoid inheritance.  That may\nbe a better way of fixing the issue.\n\nPlease don't hesitate to contact me if I may be of any assistance, e.g., in\ntesting.\n\nKind regards, John.\n```\n\nOriginal comment by `jabhodg...@gmail.com` on 21 Feb 2012 at 4:16"}}