aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/png_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/png_extractor.c')
-rw-r--r--src/plugins/png_extractor.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/plugins/png_extractor.c b/src/plugins/png_extractor.c
index 6195d0a..add1fde 100644
--- a/src/plugins/png_extractor.c
+++ b/src/plugins/png_extractor.c
@@ -42,11 +42,13 @@
42 * @return n-bytes from str followed by 0-termination, NULL on error 42 * @return n-bytes from str followed by 0-termination, NULL on error
43 */ 43 */
44static char * 44static char *
45stndup (const char *str, 45stndup (const char *str,
46 size_t n) 46 size_t n)
47{ 47{
48 char *tmp; 48 char *tmp;
49 49
50 if (n + 1 < n)
51 return NULL;
50 if (NULL == (tmp = malloc (n + 1))) 52 if (NULL == (tmp = malloc (n + 1)))
51 return NULL; 53 return NULL;
52 tmp[n] = '\0'; 54 tmp[n] = '\0';
@@ -64,7 +66,7 @@ stndup (const char *str,
64 * @return first position of 0-terminator in str, or maxlen 66 * @return first position of 0-terminator in str, or maxlen
65 */ 67 */
66static size_t 68static size_t
67stnlen (const char *str, 69stnlen (const char *str,
68 size_t maxlen) 70 size_t maxlen)
69{ 71{
70 size_t ret; 72 size_t ret;
@@ -171,7 +173,7 @@ processtEXt (struct EXTRACTOR_ExtractContext *ec,
171 if (off >= length) 173 if (off >= length)
172 return 0; /* failed to find '\0' */ 174 return 0; /* failed to find '\0' */
173 if (NULL == (keyword = EXTRACTOR_common_convert_to_utf8 ((char*) &data[off], 175 if (NULL == (keyword = EXTRACTOR_common_convert_to_utf8 ((char*) &data[off],
174 length - off, 176 length - off,
175 "ISO-8859-1"))) 177 "ISO-8859-1")))
176 return 0; 178 return 0;
177 ret = 0; 179 ret = 0;
@@ -221,6 +223,8 @@ processiTXt (struct EXTRACTOR_ExtractContext *ec,
221 compressed = data[pos++]; 223 compressed = data[pos++];
222 if (compressed && (0 != data[pos++])) 224 if (compressed && (0 != data[pos++]))
223 return 0; /* bad compression method */ 225 return 0; /* bad compression method */
226 if (pos > length)
227 return 0;
224 language = (char *) &data[pos]; 228 language = (char *) &data[pos];
225 ret = 0; 229 ret = 0;
226 if ( (stnlen (language, length - pos) > 0) && 230 if ( (stnlen (language, length - pos) > 0) &&
@@ -255,7 +259,7 @@ processiTXt (struct EXTRACTOR_ExtractContext *ec,
255 /* printf("out of memory"); */ 259 /* printf("out of memory"); */
256 return 0; /* out of memory */ 260 return 0; /* out of memory */
257 } 261 }
258 if (Z_OK == 262 if (Z_OK ==
259 (zret = uncompress ((Bytef *) buf, 263 (zret = uncompress ((Bytef *) buf,
260 &bufLen, 264 &bufLen,
261 (const Bytef *) &data[pos], length - pos))) 265 (const Bytef *) &data[pos], length - pos)))
@@ -367,10 +371,10 @@ processzTXt (struct EXTRACTOR_ExtractContext *ec,
367 /* printf("out of memory"); */ 371 /* printf("out of memory"); */
368 return 0; /* out of memory */ 372 return 0; /* out of memory */
369 } 373 }
370 if (Z_OK == 374 if (Z_OK ==
371 (zret = uncompress ((Bytef *) buf, 375 (zret = uncompress ((Bytef *) buf,
372 &bufLen, 376 &bufLen,
373 (const Bytef *) &data[off], 377 (const Bytef *) &data[off],
374 length - off))) 378 length - off)))
375 { 379 {
376 /* printf("zlib ok"); */ 380 /* printf("zlib ok"); */
@@ -380,8 +384,8 @@ processzTXt (struct EXTRACTOR_ExtractContext *ec,
380 if (Z_BUF_ERROR != zret) 384 if (Z_BUF_ERROR != zret)
381 return 0; /* unknown error, abort */ 385 return 0; /* unknown error, abort */
382 } 386 }
383 keyword = EXTRACTOR_common_convert_to_utf8 (buf, 387 keyword = EXTRACTOR_common_convert_to_utf8 (buf,
384 bufLen, 388 bufLen,
385 "ISO-8859-1"); 389 "ISO-8859-1");
386 free (buf); 390 free (buf);
387 for (i = 0; NULL != tagmap[i].name; i++) 391 for (i = 0; NULL != tagmap[i].name; i++)
@@ -432,9 +436,9 @@ processtIME (struct EXTRACTOR_ExtractContext *ec,
432 h = (unsigned char) data[8]; 436 h = (unsigned char) data[8];
433 m = (unsigned char) data[9]; 437 m = (unsigned char) data[9];
434 s = (unsigned char) data[10]; 438 s = (unsigned char) data[10];
435 snprintf (val, 439 snprintf (val,
436 sizeof (val), 440 sizeof (val),
437 "%04u-%02u-%02u %02d:%02d:%02d", 441 "%04u-%02u-%02u %02d:%02d:%02d",
438 year, mo, day, h, m, s); 442 year, mo, day, h, m, s);
439 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val); 443 ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val);
440FINISH: 444FINISH:
@@ -443,7 +447,7 @@ FINISH:
443 447
444 448
445/** 449/**
446 * Main entry method for the 'image/png' extraction plugin. 450 * Main entry method for the 'image/png' extraction plugin.
447 * 451 *
448 * @param ec extraction context provided to the plugin 452 * @param ec extraction context provided to the plugin
449 */ 453 */
@@ -465,8 +469,8 @@ EXTRACTOR_png_extract_method (struct EXTRACTOR_ExtractContext *ec)
465 ret = 0; 469 ret = 0;
466 while (0 == ret) 470 while (0 == ret)
467 { 471 {
468 if (sizeof (uint32_t) + 4 != ec->read (ec->cls, 472 if (sizeof (uint32_t) + 4 != ec->read (ec->cls,
469 &data, 473 &data,
470 sizeof (uint32_t) + 4)) 474 sizeof (uint32_t) + 4))
471 break; 475 break;
472 length = get_int_at (data); 476 length = get_int_at (data);