Show a patch.

GET /api/1.1/patches/11919/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 11919,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/11919/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11919/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210413203849.4902-1-laurent.pinchart@ideasonboard.com>",
    "date": "2021-04-13T20:38:49",
    "name": "[libcamera-devel,v2] libcamera: bound_method: Please the gcc undefined behaviour sanitizer",
    "commit_ref": "5a76290b5de9ab5bc84928bab011d70860b23b26",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "961ad768b80c7506157837b8d3fd7cde32a135ca",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11919/mbox/",
    "series": [
        {
            "id": 1922,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1922/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1922",
            "date": "2021-04-13T20:38:49",
            "name": "[libcamera-devel,v2] libcamera: bound_method: Please the gcc undefined behaviour sanitizer",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1922/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11919/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11919/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6F6EFBD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 20:39:46 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id D7926687FE;\n\tTue, 13 Apr 2021 22:39:45 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F3A8F602D1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 22:39:44 +0200 (CEST)",
            "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7C7B19F0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 22:39:44 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"jpcq9/Lf\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1618346384;\n\tbh=a37vvJFN/8e/c6r5qliL8JANrYK7SNJGsGsaqkUJfUA=;\n\th=From:To:Subject:Date:From;\n\tb=jpcq9/Lf5K89Msc7MvS29k80Cww7ofPnS8VsORPnZWGzrvaUaQXgTv6ToIFhg22kP\n\tPCcQavIZ0LFaDYHFq8Xj8YojshwcGgmDs5hsJ7DgxlI2CJDzO0UgnA1AZdrUZIIkuh\n\tzlPx48rg/F4+S9srijN5jai+0gKH+j8BamuHthGY=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 13 Apr 2021 23:38:49 +0300",
        "Message-Id": "<20210413203849.4902-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.28.1",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2] libcamera: bound_method: Please the\n\tgcc undefined behaviour sanitizer",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Enabling the gcc undefined behaviour sanitizer (with the meson configure\n-Db_sanitize=undefined option) causes many tests to fail, with errors\nsuch as the following (for test/object-invoke):\n\n------------------------------------------------------------------------\n../../include/libcamera/bound_method.h:198:27: runtime error: member access within address 0x55fcd7bfbd38 which does not point to an object of type 'BoundMethodBase'\n0x55fcd7bfbd38: note: object has invalid vptr\n fc 55 00 00  2a 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  31 00 00 00 00 00 00 00  4b c6 72 88\n              ^~~~~~~~~~~~~~~~~~~~~~~\n              invalid vptr\n../../include/libcamera/bound_method.h:198:41: runtime error: member call on null pointer of type 'struct InvokedObject'\n../../include/libcamera/bound_method.h:198:41: runtime error: member access within null pointer of type 'struct InvokedObject'\nSegmentation fault\n------------------------------------------------------------------------\n\nor\n\n------------------------------------------------------------------------\n../../include/libcamera/bound_method.h:198:27: runtime error: member access within address 0x603000006628 which does not point to an object of type 'BoundMethodBase'\n0x603000006628: note: object has invalid vptr\n 70 55 00 00  2a 00 00 00 be be be be  03 02 00 00 18 00 00 00  01 00 00 60 00 00 00 00  05 00 80 07\n              ^~~~~~~~~~~~~~~~~~~~~~~\n              invalid vptr\n=================================================================\n==941==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x603000006630 at pc 0x55704e461371 bp 0x7fff539b9040 sp 0x7fff539b9030\nREAD of size 8 at 0x603000006630 thread T0\n    #0 0x55704e461370 in libcamera::BoundMethodMember<InvokedObject, void, int>::invoke(int) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x47370)\n    #1 0x55704e4622ca in void libcamera::BoundMethodArgs<void, int>::invokePack<0ul>(libcamera::BoundMethodPackBase*, std::integer_sequence<unsigned long, 0ul>) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x482ca)\n    #2 0x55704e460a93 in libcamera::BoundMethodArgs<void, int>::invokePack(libcamera::BoundMethodPackBase*) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x46a93)\n    #3 0x7fdc38a5fec4 in libcamera::InvokeMessage::invoke() ../../src/libcamera/message.cpp:154\n    #4 0x7fdc38a62faf in libcamera::Object::message(libcamera::Message*) ../../src/libcamera/object.cpp:183\n    #5 0x7fdc38ad3742 in libcamera::Thread::dispatchMessages(libcamera::Message::Type) ../../src/libcamera/thread.cpp:575\n    #6 0x7fdc38972d8d in libcamera::EventDispatcherPoll::processEvents() ../../src/libcamera/event_dispatcher_poll.cpp:148\n    #7 0x55704e44bc15 in ObjectInvokeTest::run() (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x31c15)\n    #8 0x55704e4630ab in Test::execute() ../../test/libtest/test.cpp:28\n    #9 0x55704e44965b in main ../../test/object-invoke.cpp:204\n    #10 0x7fdc36090eba in __libc_start_main ../csu/libc-start.c:314\n    #11 0x55704e449359 in _start (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x2f359)\n\n0x603000006630 is located 0 bytes to the right of 32-byte region [0x603000006610,0x603000006630)\nallocated by thread T0 here:\n    #0 0x7fdc3ad757c7 in operator new(unsigned long) /var/tmp/portage/sys-devel/gcc-11.0.1_pre9999/work/gcc-11.0.1_pre9999/libsanitizer/asan/asan_new_delete.cpp:99\n    #1 0x55704e45afea in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x40fea)\n    #2 0x55704e45a45d in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x4045d)\n    #3 0x55704e458339 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, (__gnu_cxx::_Lock_policy)2> >&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3e339)\n    #4 0x55704e4574ad in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, int&>(libcamera::BoundMethodPack<void, int>*&, std::_Sp_alloc_shared_tag<std::allocator<libcamera::BoundMethodPack<void, int> > >, int&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3d4ad)\n    #5 0x55704e4569c7 in std::__shared_ptr<libcamera::BoundMethodPack<void, int>, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<libcamera::BoundMethodPack<void, int> >, int&>(std::_Sp_alloc_shared_tag<std::allocator<libcamera::BoundMethodPack<void, int> > >, int&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3c9c7)\n    #6 0x55704e455f9d in std::shared_ptr<libcamera::BoundMethodPack<void, int> >::shared_ptr<std::allocator<libcamera::BoundMethodPack<void, int> >, int&>(std::_Sp_alloc_shared_tag<std::allocator<libcamera::BoundMethodPack<void, int> > >, int&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3bf9d)\n    #7 0x55704e454eb5 in std::shared_ptr<libcamera::BoundMethodPack<void, int> > std::allocate_shared<libcamera::BoundMethodPack<void, int>, std::allocator<libcamera::BoundMethodPack<void, int> >, int&>(std::allocator<libcamera::BoundMethodPack<void, int> > const&, int&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3aeb5)\n    #8 0x55704e454220 in std::shared_ptr<libcamera::BoundMethodPack<void, int> > std::make_shared<libcamera::BoundMethodPack<void, int>, int&>(int&) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x3a220)\n    #9 0x55704e450e60 in libcamera::BoundMethodMember<InvokedObject, void, int>::activate(int, bool) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x36e60)\n    #10 0x55704e44efb2 in void libcamera::Object::invokeMethod<InvokedObject, void, int, int, (void*)0>(void (InvokedObject::*)(int), libcamera::ConnectionType, int) (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x34fb2)\n    #11 0x55704e44b7cc in ObjectInvokeTest::run() (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x317cc)\n    #12 0x55704e4630ab in Test::execute() ../../test/libtest/test.cpp:28\n    #13 0x55704e44965b in main ../../test/object-invoke.cpp:204\n    #14 0x7fdc36090eba in __libc_start_main ../csu/libc-start.c:314\n\nSUMMARY: AddressSanitizer: heap-buffer-overflow (libcamera/build/x86-gcc-11.0.1/test/object-invoke+0x47370) in libcamera::BoundMethodMember<InvokedObject, void, int>::invoke(int)\nShadow bytes around the buggy address:\n  0x0c067fff8c70: 00 fa fa fa 00 00 06 fa fa fa fd fd fd fd fa fa\n  0x0c067fff8c80: 00 00 06 fa fa fa 00 00 03 fa fa fa 00 00 00 05\n  0x0c067fff8c90: fa fa 00 00 04 fa fa fa 00 00 00 00 fa fa fd fd\n  0x0c067fff8ca0: fd fd fa fa fd fd fd fd fa fa fd fd fd fd fa fa\n  0x0c067fff8cb0: fd fd fd fd fa fa 00 00 00 00 fa fa 00 00 00 00\n=>0x0c067fff8cc0: fa fa 00 00 00 00[fa]fa fd fd fd fa fa fa fa fa\n  0x0c067fff8cd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n  0x0c067fff8ce0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n  0x0c067fff8cf0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n  0x0c067fff8d00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\n  0x0c067fff8d10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa\nShadow byte legend (one shadow byte represents 8 application bytes):\n  Addressable:           00\n  Partially addressable: 01 02 03 04 05 06 07\n  Heap left redzone:       fa\n  Freed heap region:       fd\n  Stack left redzone:      f1\n  Stack mid redzone:       f2\n  Stack right redzone:     f3\n  Stack after return:      f5\n  Stack use after scope:   f8\n  Global redzone:          f9\n  Global init order:       f6\n  Poisoned by user:        f7\n  Container overflow:      fc\n  Array cookie:            ac\n  Intra object redzone:    bb\n  ASan internal:           fe\n  Left alloca redzone:     ca\n  Right alloca redzone:    cb\n  Shadow gap:              cc\n==941==ABORTING\n------------------------------------------------------------------------\n\nThe root cause isn't clear, but this change fixes the issue. It may be a\nbug in gcc.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nAcked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\nChanges since v1:\n\n- Add another error to the commit message\n- Expand the change to two other locations, for consistency\n\n---\n include/libcamera/bound_method.h | 18 ++++++++++++------\n 1 file changed, 12 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/include/libcamera/bound_method.h b/include/libcamera/bound_method.h\nindex f216e3b56826..4fc445ecd191 100644\n--- a/include/libcamera/bound_method.h\n+++ b/include/libcamera/bound_method.h\n@@ -153,8 +153,10 @@ public:\n \n \tR activate(Args... args, bool deleteMethod = false) override\n \t{\n-\t\tif (!this->object_)\n-\t\t\treturn (static_cast<T *>(this->obj_)->*func_)(args...);\n+\t\tif (!this->object_) {\n+\t\t\tT *obj = static_cast<T *>(this->obj_);\n+\t\t\treturn (obj->*func_)(args...);\n+\t\t}\n \n \t\tauto pack = std::make_shared<PackType>(args...);\n \t\tbool sync = BoundMethodBase::activatePack(pack, deleteMethod);\n@@ -163,7 +165,8 @@ public:\n \n \tR invoke(Args... args) override\n \t{\n-\t\treturn (static_cast<T *>(this->obj_)->*func_)(args...);\n+\t\tT *obj = static_cast<T *>(this->obj_);\n+\t\treturn (obj->*func_)(args...);\n \t}\n \n private:\n@@ -186,8 +189,10 @@ public:\n \n \tvoid activate(Args... args, bool deleteMethod = false) override\n \t{\n-\t\tif (!this->object_)\n-\t\t\treturn (static_cast<T *>(this->obj_)->*func_)(args...);\n+\t\tif (!this->object_) {\n+\t\t\tT *obj = static_cast<T *>(this->obj_);\n+\t\t\treturn (obj->*func_)(args...);\n+\t\t}\n \n \t\tauto pack = std::make_shared<PackType>(args...);\n \t\tBoundMethodBase::activatePack(pack, deleteMethod);\n@@ -195,7 +200,8 @@ public:\n \n \tvoid invoke(Args... args) override\n \t{\n-\t\t(static_cast<T *>(this->obj_)->*func_)(args...);\n+\t\tT *obj = static_cast<T *>(this->obj_);\n+\t\treturn (obj->*func_)(args...);\n \t}\n \n private:\n",
    "prefixes": [
        "libcamera-devel",
        "v2"
    ]
}