Patch Detail
Show a patch.
GET /api/patches/18522/?format=api
{ "id": 18522, "url": "https://patchwork.libcamera.org/api/patches/18522/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18522/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>", "date": "2023-04-04T16:11:16", "name": "[libcamera-devel] libcamera: controls: guard ControlInfoMap against nullptr idmap_", "commit_ref": "3dc2605bda52b627f6e009ef4a3c8360d00e358a", "pull_url": null, "state": "accepted", "archived": false, "hash": "037d4c7fff653f3b34df2ae166489959d44ef7dd", "submitter": { "id": 153, "url": "https://patchwork.libcamera.org/api/people/153/?format=api", "name": "Mattijs Korpershoek", "email": "mkorpershoek@baylibre.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18522/mbox/", "series": [ { "id": 3835, "url": "https://patchwork.libcamera.org/api/series/3835/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3835", "date": "2023-04-04T16:11:16", "name": "[libcamera-devel] libcamera: controls: guard ControlInfoMap against nullptr idmap_", "version": 1, "mbox": "https://patchwork.libcamera.org/series/3835/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18522/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18522/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 8886CC0F2A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 4 Apr 2023 16:11:24 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AF0FA62724;\n\tTue, 4 Apr 2023 18:11:23 +0200 (CEST)", "from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com\n\t[IPv6:2a00:1450:4864:20::42b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 33694626DB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 4 Apr 2023 18:11:22 +0200 (CEST)", "by mail-wr1-x42b.google.com with SMTP id i9so33401024wrp.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 04 Apr 2023 09:11:22 -0700 (PDT)", "from [192.168.1.20] ([2a01:cb19:85e6:1900:2bf7:7388:731d:c4e1])\n\tby smtp.gmail.com with ESMTPSA id\n\tm2-20020a5d4a02000000b002d75ef32032sm12625130wrq.68.2023.04.04.09.11.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 04 Apr 2023 09:11:21 -0700 (PDT)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1680624683;\n\tbh=QcSH2iUvuO32L5ZbL6Mv7CNgoHp9OFYOONs6/dH1BPg=;\n\th=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=LhgqvoCY9n7bqXNsY54fb8gXSbaaVDahrqAUVDbN/z/2F2U3Yd47Tfy6w1dYLY6um\n\tjeVBir9J9ijjtZmZP2jTqursBPxlSjsSzdlHvdLBnXVE1Vc6de3n1aFBU+GeaxKemF\n\tpu44A0KV7r+7V7RSX1I7ZWIHkn0PE7UDeoE2YsvnQN8hsGBPzEsDmriSiKAKcbmDdJ\n\t9EZNzMt63rQw3gSYpJ9PorKshE14gIPmxHok6HLyQ5PEw8QTpOFW8uFyoqKmvgCVjZ\n\tTnm3B3xrSFpcK3Z+bQ3yl1Awh6ACXAj51by25RDeldIhHzB7LrYMh2Kdf8mpg3zUbq\n\tMWarEawZQUdxw==", "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=baylibre-com.20210112.gappssmtp.com; s=20210112; t=1680624682;\n\th=cc:to:message-id:content-transfer-encoding:mime-version:subject\n\t:date:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=WldeUi+pF2aTTNBdp8g3pArwejx+IeB0Qyypmeuvzbc=;\n\tb=iMSCtHLWd3untLOLr5dHQuYTPTXzr7OyqocIoMZTGy+Gm4wT3SeewY8Wdy+mggRze6\n\toFBAeZF/j+Oa9Uwhv4fUVVtxL275+XkixhMOwcnEs+7f7/jgJRL4/jvz0Mibjy5xUYls\n\tfgqmR9wUjKi6F2GDbgSPg6A2avFrjTE2MuJALmNFLjcxgamMuuEbWE+cbxgPBWZEGRgZ\n\tramzV1d/cXmRIamW09jbzX+LYyNHCS/2prQlD201LJO7sA/H3BKrRN8HJpwFC9CeYAb/\n\tRSVXw5L+Uj9NJkeDRBn6C7s/sZV9FiXUk8C0/qoFug/RoZdjlM2UawZKQRV/DPV3Byxa\n\tRVlw==" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected)\n\theader.d=baylibre-com.20210112.gappssmtp.com\n\theader.i=@baylibre-com.20210112.gappssmtp.com header.b=\"iMSCtHLW\"; \n\tdkim-atps=neutral", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112; t=1680624682;\n\th=cc:to:message-id:content-transfer-encoding:mime-version:subject\n\t:date:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=WldeUi+pF2aTTNBdp8g3pArwejx+IeB0Qyypmeuvzbc=;\n\tb=LPVddROjS8ttNxVuMI1X1FCiiwD0L7yC8XlrPRKMaMKQjfQFK1IKhJMHNiphps5L3i\n\tHiabZDowb813ACbqcjg/RYMC5zmfGtbwQQta4CuRZjtrbGwmxg5m/r+gYWD36vdZWIXM\n\tVU0xCLF5pFM/Az/vWHCLPPeDji3I+O/uYFwmz6YYSmK0+umDVqd/GZDGFhnD40lFLtcZ\n\tZA9DRZ/emMovXkARPjUBvJsZGdJToOQ8rNHFtt2QldhWiucPLwY8vAVEtZ5yGvYlYeDS\n\tE3HiQVQ0DbPnXfB6esBFpj4YWYq8Q7ezAo6abAo4Dex/HGSV7mnISCbS0wbV6QTh1Kdr\n\tvhEg==", "X-Gm-Message-State": "AAQBX9e6Euu3GzFnChET/Uve65sDnerBNmBQwecj29LBDal/oFuTM4V9\n\tO8Zs6bVYi7Qvzl4nX3pp+CPjFg==", "X-Google-Smtp-Source": "AKy350YB4jsiThSNVibgmfJoZSvmbnpWamfhEwWH9xTzI5TTK3TW2CkSIoOkE4SATM2dtsCt8lH6rg==", "X-Received": "by 2002:adf:e8cb:0:b0:2da:45f4:c053 with SMTP id\n\tk11-20020adfe8cb000000b002da45f4c053mr1885307wrn.52.1680624681754; \n\tTue, 04 Apr 2023 09:11:21 -0700 (PDT)", "Date": "Tue, 04 Apr 2023 18:11:16 +0200", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Message-Id": "<20230404-guard-idmap-v1-1-b75c2d924caf@baylibre.com>", "X-B4-Tracking": "v=1; b=H4sIACNMLGQC/x2NQQqDMBBFryKzbmiS6qK9SuliTEYziEmYwVIQ7\n\t97o8j3+4++gJEwKr24HoS8rl9zA3ToICfNMhmNj8NY/bG97M28osckVq3HxOUzeWYsBoRUjKpl\n\tRMId0NutSpJJoKrTcg/I5qUIT/67D9+c4/hu8HUOAAAAA", "To": "libcamera-devel@lists.libcamera.org", "X-Mailer": "b4 0.13-dev-00303", "Subject": "[libcamera-devel] [PATCH] libcamera: controls: guard ControlInfoMap\n\tagainst nullptr idmap_", "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>", "From": "Mattijs Korpershoek via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>", "Reply-To": "Mattijs Korpershoek <mkorpershoek@baylibre.com>", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "It's possible to construct a Camera with an unsafe controlInfo_.\nThis is the case in the Simple pipeline, where the camera controls are\nnot populated.\n\nWith Simple, if we attempt to set a Control, we end up with a segfault\nbecause the default constructor for ControlInfoMap doesn't\nintialized idmap_ which is initialized at class declaration time as\n\n const ControlIdMap *idmap_ = nullptr;\n\nAdd some safeguards in ControlInfoMap to handle this case.\n\nLink: http://codepad.org/CiLLcPNW\nLink: https://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\nSuggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>\n---\nI have build-tested this against master and functionally tested on a\nv0.0.4 android integration branch.\n\nI've tested that i'm able to do a camera preview even when the\nScalerCrop control is unavailble.\n\nNote that Jacopo already discussed alternative implementation by making\nidmap_ an instance instead of a pointer, but that seemed not a good idea\neither:\n\nhttps://lists.libcamera.org/pipermail/libcamera-devel/2023-April/037439.html\n---\n src/libcamera/controls.cpp | 16 ++++++++++++++++\n 1 file changed, 16 insertions(+)\n\n\n---\nbase-commit: ac7511dc4c594f567ddff27ccc02c30bf6c00bfd\nchange-id: 20230404-guard-idmap-1d95f2100aca\n\nBest regards,", "diff": "diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 6dbf9b348709..b808116c01e5 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -677,6 +677,9 @@ ControlInfoMap::ControlInfoMap(Map &&info, const ControlIdMap &idmap)\n \n bool ControlInfoMap::validate()\n {\n+\tif (!idmap_)\n+\t\treturn false;\n+\n \tfor (const auto &ctrl : *this) {\n \t\tconst ControlId *id = ctrl.first;\n \t\tauto it = idmap_->find(id->id());\n@@ -719,6 +722,8 @@ bool ControlInfoMap::validate()\n */\n ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n {\n+\tASSERT(idmap_);\n+\n \treturn at(idmap_->at(id));\n }\n \n@@ -729,6 +734,8 @@ ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id)\n */\n const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n {\n+\tASSERT(idmap_);\n+\n \treturn at(idmap_->at(id));\n }\n \n@@ -739,6 +746,9 @@ const ControlInfoMap::mapped_type &ControlInfoMap::at(unsigned int id) const\n */\n ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n {\n+\tif (!idmap_)\n+\t\treturn 0;\n+\n \t/*\n \t * The ControlInfoMap and its idmap have a 1:1 mapping between their\n \t * entries, we can thus just count the matching entries in idmap to\n@@ -755,6 +765,9 @@ ControlInfoMap::size_type ControlInfoMap::count(unsigned int id) const\n */\n ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n {\n+\tif (!idmap_)\n+\t\treturn end();\n+\n \tauto iter = idmap_->find(id);\n \tif (iter == idmap_->end())\n \t\treturn end();\n@@ -770,6 +783,9 @@ ControlInfoMap::iterator ControlInfoMap::find(unsigned int id)\n */\n ControlInfoMap::const_iterator ControlInfoMap::find(unsigned int id) const\n {\n+\tif (!idmap_)\n+\t\treturn end();\n+\n \tauto iter = idmap_->find(id);\n \tif (iter == idmap_->end())\n \t\treturn end();\n", "prefixes": [ "libcamera-devel" ] }