[libcamera-devel] [PATCH v2] android: jpeg: exif: Sanitize ASCII strings with utils::toAscii()
Umang Jain
email at uajain.com
Mon Oct 5 18:57:01 CEST 2020
Use the newly introduced utils::toAscii() utility to remove all
non-ASCII characters for EXIF_FORMAT_ASCII strings.
Signed-off-by: Umang Jain <email at uajain.com>
---
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);
}
--
2.26.2
More information about the libcamera-devel
mailing list