mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-25 17:45:06 +03:00
android: jpeg: exif: Sanitize ASCII strings with utils::toAscii()
Use the newly introduced utils::toAscii() utility to remove all non-ASCII characters for EXIF_FORMAT_ASCII strings. Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
c57622d95f
commit
6feebf297e
1 changed files with 21 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
|||
#include "exif.h"
|
||||
|
||||
#include "libcamera/internal/log.h"
|
||||
#include "libcamera/internal/utils.h"
|
||||
|
||||
using namespace libcamera;
|
||||
|
||||
|
@ -171,15 +172,31 @@ 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();
|
||||
std::string ascii;
|
||||
size_t length;
|
||||
const char *str;
|
||||
|
||||
if (format == EXIF_FORMAT_ASCII) {
|
||||
ascii = utils::toAscii(item);
|
||||
str = ascii.c_str();
|
||||
|
||||
/* Pad 1 extra byte to null-terminate the ASCII string. */
|
||||
length = ascii.length() + 1;
|
||||
} else {
|
||||
str = item.c_str();
|
||||
|
||||
/*
|
||||
* Strings stored in different formats (EXIF_FORMAT_UNDEFINED)
|
||||
* are not null-terminated.
|
||||
*/
|
||||
length = item.length();
|
||||
}
|
||||
|
||||
ExifEntry *entry = createEntry(ifd, tag, format, length, length);
|
||||
if (!entry)
|
||||
return;
|
||||
|
||||
memcpy(entry->data, item.c_str(), length);
|
||||
memcpy(entry->data, str, length);
|
||||
exif_entry_unref(entry);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue