From patchwork Sat May 15 18:38:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12304 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E8509C31FB for ; Sat, 15 May 2021 18:38:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EB6AE6891E; Sat, 15 May 2021 20:38:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oK0XEIbA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0AFE66891B for ; Sat, 15 May 2021 20:38:40 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8BCBA559; Sat, 15 May 2021 20:38:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1621103919; bh=CnncbO62OunficC/7qsarbjsqDtx4b26YIPxesqOXcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oK0XEIbA8p655M/X/liDJDdgCPtjTcd8hPLQXlgh3Ea3gHwPEVLAgUDwCgLuWOP4a ziyvP/mwix372hZ1NuzMGND0Gb2cxdGqeQw5zVRuFvxxvg7M+ljwCkeJMlpKKU27z4 MOHhal21Nih5F90krdrRVHYvDdoTDO4R9ADTWh8Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 15 May 2021 21:38:23 +0300 Message-Id: <20210515183826.21003-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> References: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] android: camera_metadata: Rename sizeofT argument to elementSize X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The sizeofT argument to CameraMetadata::addEntry() stores the size of one element. Its name is a bit cryptic as the function isn't a template function with a typename T. Rename it to elementSize. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- src/android/camera_metadata.cpp | 4 ++-- src/android/camera_metadata.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp index bf8d2781cc21..59366c50cc16 100644 --- a/src/android/camera_metadata.cpp +++ b/src/android/camera_metadata.cpp @@ -110,12 +110,12 @@ bool CameraMetadata::resize(size_t count, size_t size) } bool CameraMetadata::addEntry(uint32_t tag, const void *data, size_t count, - size_t sizeofT) + size_t elementSize) { if (!valid_) return false; - if (!resize(1, count * sizeofT)) { + if (!resize(1, count * elementSize)) { LOG(CameraMetadata, Error) << "Failed to resize"; valid_ = false; return false; diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index 07afd4b25ae7..56df6f1c9008 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -72,7 +72,8 @@ public: return updateEntry(tag, data.data(), data.size()); } - bool addEntry(uint32_t tag, const void *data, size_t count, size_t sizeofT); + bool addEntry(uint32_t tag, const void *data, size_t count, + size_t elementSize); bool updateEntry(uint32_t tag, const void *data, size_t count); camera_metadata_t *get(); From patchwork Sat May 15 18:38:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12305 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9079BC31FB for ; Sat, 15 May 2021 18:38:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 564796891F; Sat, 15 May 2021 20:38:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="EH2seeLy"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8F7576891B for ; Sat, 15 May 2021 20:38:40 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EA8D9436; Sat, 15 May 2021 20:38:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1621103920; bh=r1xv+9WpF9UfQq7xQQxmyGDXXSzvFhn68xI6CqXPaYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EH2seeLyQZscXJ+DwwN5eLdWhNfg27NAUMfbfeKUEAQuObITQojTx6RHkEGQ781Y/ uNNmvTo+awfrQrHSo0vBXgv2erLRRLmk5HL51SatN/kRErTkNc1apEJLTeWqOZN/eC zCEVxPfoxKIuKqOskUE2+kh1XTOScUliVv90OUac= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 15 May 2021 21:38:24 +0300 Message-Id: <20210515183826.21003-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> References: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] android: camera_metadata: Constify argument to addEntry() and updateEntry() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The addEntry() and updateEntry() overrides that take a reference to a container don't need to modify the container. Make it const. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- src/android/camera_metadata.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index 56df6f1c9008..f95c34581fe4 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -42,7 +42,7 @@ public: template - bool addEntry(uint32_t tag, S &data) + bool addEntry(uint32_t tag, const S &data) { return addEntry(tag, data.data(), data.size(), sizeof(T)); } @@ -67,7 +67,7 @@ public: template - bool updateEntry(uint32_t tag, S &data) + bool updateEntry(uint32_t tag, const S &data) { return updateEntry(tag, data.data(), data.size()); } From patchwork Sat May 15 18:38:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12306 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1B2A7C31FB for ; Sat, 15 May 2021 18:38:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CAE1A68920; Sat, 15 May 2021 20:38:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kcFDpSrD"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D6DAF6891B for ; Sat, 15 May 2021 20:38:40 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D72C559; Sat, 15 May 2021 20:38:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1621103920; bh=/r7G+YIxnwm+9weY/pVPn7vH5fKtgLvNaRZYSy8WzhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcFDpSrDhA47yHivKVwfAvs8kp98H3643RAXZQ+qt4tRmqc8MyQJO8OP+NoRjJboG j7H5Kim6Ajcpj0A4sDI9Zlom9rjV8iRlOutJ601QGHuOZFO0qzEcdvWCdCZYtGMmkH qD4Hyt9KwTPCUM+8M4C08A4OQeuMOnHcgPeB3LMo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 15 May 2021 21:38:25 +0300 Message-Id: <20210515183826.21003-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> References: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] android: camera_metadata: Make internal functions private X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The resize() function and the addEntry() override that takes a void pointer are not meant to be called by the user of the CameraMetadata class. Make them private. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- src/android/camera_metadata.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index f95c34581fe4..d7c8d9df689f 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -24,7 +24,6 @@ public: CameraMetadata &operator=(const CameraMetadata &other); bool isValid() const { return valid_; } - bool resize(size_t count, size_t size); bool getEntry(uint32_t tag, camera_metadata_ro_entry_t *entry) const; template X-Patchwork-Id: 12307 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 9F4BEC31FB for ; Sat, 15 May 2021 18:38:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 358066891C; Sat, 15 May 2021 20:38:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jNT0V874"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8E69C68922 for ; Sat, 15 May 2021 20:38:41 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D9ADC436; Sat, 15 May 2021 20:38:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1621103921; bh=hFx1vZWboqmba7kNCvzD3RUJNZ78+tS9s2S2+nB4hWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jNT0V874KtyL5ySThaeCe1lguZ+HhZChGc1BnNvkSfoouf7hyrom3a/Yh9QmN4H7L 0tIxgSdTEqS+W5VoIPCqXPspySxAuyriB4azuruNVr8j0a0gHfTaWO90ljVn3euYpU LotpLSnisaarUy1e98X3c8Q1nZen0XMFVNTByjLI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 15 May 2021 21:38:26 +0300 Message-Id: <20210515183826.21003-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> References: <20210515183826.21003-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] android: camera_metadata: Add type sanity check to updateEntry() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraMetadata::updateEntry() functions cast the data pointer to a void pointer, which is then used internally to call update_camera_metadata_entry(). If the caller passes a pointer to an incorrect data type, the behaviour is undefined, with possible crashes if the incorrect data type is smaller than expected by the Android metadata library. To avoid crashes, make all public updateEntry() functions take typed pointers, and pass the element size to the internal function. The element size is then checked against the expected size, and an error message logged if they don't match. This won't catch incorrect data types that have the same size as the correct type, but will at least avoid potential crashes. Signed-off-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Kieran Bingham --- src/android/camera_metadata.cpp | 11 ++++++++++- src/android/camera_metadata.h | 12 +++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/android/camera_metadata.cpp b/src/android/camera_metadata.cpp index 59366c50cc16..3eb71d7f7d9d 100644 --- a/src/android/camera_metadata.cpp +++ b/src/android/camera_metadata.cpp @@ -137,7 +137,8 @@ bool CameraMetadata::addEntry(uint32_t tag, const void *data, size_t count, return false; } -bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t count) +bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t count, + size_t elementSize) { if (!valid_) return false; @@ -152,6 +153,14 @@ bool CameraMetadata::updateEntry(uint32_t tag, const void *data, size_t count) return false; } + if (camera_metadata_type_size[entry.type] != elementSize) { + const char *name = get_camera_metadata_tag_name(tag); + LOG(CameraMetadata, Error) + << "Invalid element size for tag " + << (name ? name : "") << ": not present"; + return false; + } + size_t oldSize = calculate_camera_metadata_entry_data_size(entry.type, entry.count); diff --git a/src/android/camera_metadata.h b/src/android/camera_metadata.h index d7c8d9df689f..f8f2a0d23aa3 100644 --- a/src/android/camera_metadata.h +++ b/src/android/camera_metadata.h @@ -55,7 +55,7 @@ public: template bool updateEntry(uint32_t tag, const T &data) { - return updateEntry(tag, &data, 1); + return updateEntry(tag, &data, 1, sizeof(T)); } template @@ -68,10 +68,14 @@ public: typename T = typename S::value_type> bool updateEntry(uint32_t tag, const S &data) { - return updateEntry(tag, data.data(), data.size()); + return updateEntry(tag, data.data(), data.size(), sizeof(T)); } - bool updateEntry(uint32_t tag, const void *data, size_t count); + template + bool updateEntry(uint32_t tag, const T *data, size_t count) + { + return updateEntry(tag, data, count, sizeof(T)); + } camera_metadata_t *get(); const camera_metadata_t *get() const; @@ -80,6 +84,8 @@ private: bool resize(size_t count, size_t size); bool addEntry(uint32_t tag, const void *data, size_t count, size_t elementSize); + bool updateEntry(uint32_t tag, const void *data, size_t count, + size_t elementSize); camera_metadata_t *metadata_; bool valid_;