[libcamera-devel,v2,1/2] android: jpeg: exif: Pad extra byte only for ASCII format in setString()

Message ID 20200924183642.7674-2-email@uajain.com
State Accepted
Commit 51bfc823921095b301a6c68e9e59d8cb4e2ffc2d
Headers show
Series
  • android: jpeg: exif: Set timezone information
Related show

Commit Message

Umang Jain Sept. 24, 2020, 6:36 p.m. UTC
The EXIF standard states that EXIF_FORMAT_UNDEFINED shall not be
terminated with NULL. The patch implements this particular detail and
pad one extra byte for EXIF_FORMAT_ASCII to null-terminate strings.

Signed-off-by: Umang Jain <email@uajain.com>
---
 src/android/jpeg/exif.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart Sept. 29, 2020, 2:50 a.m. UTC | #1
Hi Umang,

Thank you for the patch.

On Fri, Sep 25, 2020 at 12:06:41AM +0530, Umang Jain wrote:
> The EXIF standard states that EXIF_FORMAT_UNDEFINED shall not be
> terminated with NULL. The patch implements this particular detail and
> pad one extra byte for EXIF_FORMAT_ASCII to null-terminate strings.
> 
> Signed-off-by: Umang Jain <email@uajain.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/android/jpeg/exif.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
> index c0dbfcc..a5674b3 100644
> --- a/src/android/jpeg/exif.cpp
> +++ b/src/android/jpeg/exif.cpp
> @@ -157,8 +157,9 @@ 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. */
> -	size_t length = item.length() + 1;
> +	/* Pad 1 extra byte for null-terminated string in ASCII format. */
> +	size_t length = format == EXIF_FORMAT_ASCII ?
> +			item.length() + 1 : item.length();
>  
>  	ExifEntry *entry = createEntry(ifd, tag, format, length, length);
>  	if (!entry)

Patch

diff --git a/src/android/jpeg/exif.cpp b/src/android/jpeg/exif.cpp
index c0dbfcc..a5674b3 100644
--- a/src/android/jpeg/exif.cpp
+++ b/src/android/jpeg/exif.cpp
@@ -157,8 +157,9 @@  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. */
-	size_t length = item.length() + 1;
+	/* Pad 1 extra byte for null-terminated string in ASCII format. */
+	size_t length = format == EXIF_FORMAT_ASCII ?
+			item.length() + 1 : item.length();
 
 	ExifEntry *entry = createEntry(ifd, tag, format, length, length);
 	if (!entry)