summaryrefslogtreecommitdiff
path: root/exif.c
diff options
context:
space:
mode:
authorTakahiro Okada <takahiro.okada@sonyericsson.com>2011-01-27 20:06:00 +0900
committerJohan Redestig <johan.redestig@sonyericsson.com>2011-05-26 15:56:08 +0200
commit2645b48159b2928fe388c6c84991b956f01e8f4e (patch)
treedfa6c104049d56482864ac335ce21ae60b4667d2 /exif.c
parentc5a256626bd67390bab579f4e52f27bdd6ce5b7c (diff)
downloadjhead-2645b48159b2928fe388c6c84991b956f01e8f4e.tar.gz
Make create_EXIF allocate enough memory
The create_EXIF method crashes if over 1K bytes exif header is passed because only 1K byte is allocated for exif header. It is hard to calcurate exact nessesary size for editing the exif header dynamically, so this value is changed to the mamixmum size of exif, 64K. Change-Id: Ia2c8481da5130f02ec8f1c63ece9aa4289b1ad5f
Diffstat (limited to 'exif.c')
-rw-r--r--exif.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/exif.c b/exif.c
index 3747bf6..7efb6fe 100644
--- a/exif.c
+++ b/exif.c
@@ -1168,12 +1168,8 @@ char* formatStr(int format) {
// Create minimal exif header - just date and thumbnail pointers,
// so that date and thumbnail may be filled later.
//--------------------------------------------------------------------------
-void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+static void create_EXIF_internal(ExifElement_t* elements, int exifTagCount, int gpsTagCount, char* Buffer)
{
- // TODO: We need to dynamically allocate this buffer and resize it when
- // necessary while writing so we don't do a buffer overflow.
- char Buffer[1024];
-
unsigned short NumEntries;
int DataWriteIndex;
int DirIndex;
@@ -1384,6 +1380,21 @@ void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
}
}
+void create_EXIF(ExifElement_t* elements, int exifTagCount, int gpsTagCount)
+{
+ // It is hard to calculate exact necessary size for editing the exif
+ // header dynamically, so we are using the maximum size of EXIF, 64K
+ const int EXIF_MAX_SIZE = 1024*64;
+ char* Buffer = malloc(EXIF_MAX_SIZE);
+
+ if (Buffer != NULL) {
+ create_EXIF_internal(elements, exifTagCount, gpsTagCount, Buffer);
+ free(Buffer);
+ } else {
+ ErrFatal("Could not allocate memory");
+ }
+}
+
//--------------------------------------------------------------------------
// Cler the rotation tag in the exif header to 1.
//--------------------------------------------------------------------------