From patchwork Mon Oct 5 13:11:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9963 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 3AA14C3B5D for ; Mon, 5 Oct 2020 13:11:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BC77563BED; Mon, 5 Oct 2020 15:11:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="tN2iYHAx"; dkim-atps=neutral Received: from mail.uajain.com (static.126.159.217.95.clients.your-server.de [95.217.159.126]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 670EF63BD5 for ; Mon, 5 Oct 2020 15:11:45 +0200 (CEST) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1601903504; bh=azo16TZcaq8xR0sVR2t+K45QyiikEXctw+ArawBm+bQ=; h=From:To:Cc:Subject; b=tN2iYHAxxMv+ylAu6IGrQpiM8BN198tat1ZDMNzcSMr7rnGvFc5dzWNLI96dReyZ4 h4jX6v4hM5OZwojOXaJ4zlYUjpIY2vyTZzcYteW5G2Lxp3SVyc3NEPGn9CaDJNA8OS w5YHn8u2Rsjyesu3c1D+4zxhaH1RykXlbxnVKhiRgg5DeKZQCnWTd12Ni2n9OwDxmX G/KILnFvB3P3SgXWQ8DeorPvsA/C3ZQlIG0N0kbU97jAVFnEPGtR7V6a3yGN6cVcWY tcNIMZSv5bpXC1p0E9XCrkR+YAayPolHEMnYboBFhkzJnelayVTz4KAkX9t5DDRJ7l ZsVYilrtYHPTQ== To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 18:41:37 +0530 Message-Id: <20201005131137.50124-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH] android: jpeg: exif: Sanitize ASCII strings with utils::toAscii() 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" Use the newly introduced utils::toAscii() utility to remove all non-ASCII characters for EXIF_FORMAT_ASCII strings. Signed-off-by: Umang Jain Reviewed-by: Kieran Bingham --- src/android/jpeg/exif.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 3fd5d55..bd528a7 100644 --- a/src/android/jpeg/exif.cpp +++ b/src/android/jpeg/exif.cpp @@ -8,6 +8,7 @@ #include "exif.h" #include "libcamera/internal/log.h" +#include "libcamera/internal/utils.h" using namespace libcamera; @@ -171,15 +172,19 @@ void Exif::setRational(ExifIfd ifd, ExifTag tag, ExifRational item) void Exif::setString(ExifIfd ifd, ExifTag tag, ExifFormat format, const std::string &item) { - /* Pad 1 extra byte for null-terminated string in ASCII format. */ - size_t length = format == EXIF_FORMAT_ASCII ? - item.length() + 1 : item.length(); + size_t length = item.length(); + std::string str = item; + if (format == EXIF_FORMAT_ASCII) { + str = utils::toAscii(str); + /* Pad 1 extra byte to null-terminate the ASCII string. */ + length += 1; + } ExifEntry *entry = createEntry(ifd, tag, format, length, length); if (!entry) return; - memcpy(entry->data, item.c_str(), length); + memcpy(entry->data, str.c_str(), length); exif_entry_unref(entry); }