From patchwork Mon Oct 5 16:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9964 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 80C58C3B5D for ; Mon, 5 Oct 2020 16:57:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 09BA463BFE; Mon, 5 Oct 2020 18:57:09 +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="qbcIASXk"; 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 C9E0F63BED for ; Mon, 5 Oct 2020 18:57:07 +0200 (CEST) From: Umang Jain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=uajain.com; s=mail; t=1601917027; bh=sEUbrg58M7L71EHmbbAPqTtFcaJlToAkzriHSB858Nk=; h=From:To:Cc:Subject; b=qbcIASXkOm28FLEtstx7gPO3i7IUtfM2JJPGTF3CxJCNfC1B1qgDLdnySyZsEQ8wE 8ozb8d0nAVEuti/35cySp24NFdbjyyndvjzJ53OPaVDs2nr0oGHYCWyZAjNUD8hLjM CeizQ7jcNYxyKB7LeUYn/SeBHAeR+6yr3ctYBqOVxOp26aMq7pO7ew8yXqbfEymdmF Izqu4tINs7sUezUCyTPA2/MWugANgMPNsMnEsdcIv4D+7hBuMPLOpEw5t5lJsb+DHB GR+WGqDhrb0UYeGOJHMp/a402h1XAPiU1I1BFDbOxIuUeMDEREvCbCpmpqZbTvEAVF /KPg84SkmBCVg== To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 22:27:01 +0530 Message-Id: <20201005165701.77469-1-email@uajain.com> Mime-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] 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 --- src/android/jpeg/exif.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) --- Changes in v2: - Set new length for sanitized string. diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp index 3fd5d55..56e3c6a 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,22 @@ 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); + /* + * Get new length and pad 1 extra byte to null-terminate + * the ASCII string. + */ + length = str.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); }