diff options
Diffstat (limited to 'src/plugins/png_extractor.c')
-rw-r--r-- | src/plugins/png_extractor.c | 128 |
1 files changed, 78 insertions, 50 deletions
diff --git a/src/plugins/png_extractor.c b/src/plugins/png_extractor.c index 07243a1..978cd8b 100644 --- a/src/plugins/png_extractor.c +++ b/src/plugins/png_extractor.c | |||
@@ -85,17 +85,21 @@ static struct | |||
85 | 85 | ||
86 | 86 | ||
87 | static int | 87 | static int |
88 | processtEXt (const char *data, | 88 | processtEXt (struct EXTRACTOR_PluginList *plugin, |
89 | unsigned int length, | 89 | unsigned int length, |
90 | EXTRACTOR_MetaDataProcessor proc, | 90 | EXTRACTOR_MetaDataProcessor proc, |
91 | void *proc_cls) | 91 | void *proc_cls) |
92 | { | 92 | { |
93 | unsigned char *data; | ||
93 | char *keyword; | 94 | char *keyword; |
94 | unsigned int off; | 95 | unsigned int off; |
95 | int i; | 96 | int i; |
96 | int ret; | 97 | int ret; |
97 | 98 | ||
98 | data += 4; | 99 | if (length != pl_read (plugin, &data, length)) |
100 | return 1; | ||
101 | |||
102 | //data += 4; | ||
99 | off = stnlen (data, length) + 1; | 103 | off = stnlen (data, length) + 1; |
100 | if (off >= length) | 104 | if (off >= length) |
101 | return 0; /* failed to find '\0' */ | 105 | return 0; /* failed to find '\0' */ |
@@ -115,16 +119,17 @@ processtEXt (const char *data, | |||
115 | i++; | 119 | i++; |
116 | } | 120 | } |
117 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword); | 121 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, keyword); |
118 | FINISH: | 122 | FINISH: |
119 | return ret; | 123 | return ret; |
120 | } | 124 | } |
121 | 125 | ||
122 | static int | 126 | static int |
123 | processiTXt (const char *data, | 127 | processiTXt (struct EXTRACTOR_PluginList *plugin, |
124 | unsigned int length, | 128 | unsigned int length, |
125 | EXTRACTOR_MetaDataProcessor proc, | 129 | EXTRACTOR_MetaDataProcessor proc, |
126 | void *proc_cls) | 130 | void *proc_cls) |
127 | { | 131 | { |
132 | unsigned char *data; | ||
128 | unsigned int pos; | 133 | unsigned int pos; |
129 | char *keyword; | 134 | char *keyword; |
130 | const char *language; | 135 | const char *language; |
@@ -137,8 +142,11 @@ processiTXt (const char *data, | |||
137 | int ret; | 142 | int ret; |
138 | int zret; | 143 | int zret; |
139 | 144 | ||
145 | if (length != pl_read (plugin, &data, length)) | ||
146 | return 1; | ||
147 | |||
140 | pos = stnlen (data, length) + 1; | 148 | pos = stnlen (data, length) + 1; |
141 | if (pos + 3 >= length) | 149 | if (pos >= length) |
142 | return 0; | 150 | return 0; |
143 | compressed = data[pos++]; | 151 | compressed = data[pos++]; |
144 | if (compressed && (data[pos++] != 0)) | 152 | if (compressed && (data[pos++] != 0)) |
@@ -148,8 +156,7 @@ processiTXt (const char *data, | |||
148 | if (stnlen (language, length - pos) > 0) | 156 | if (stnlen (language, length - pos) > 0) |
149 | { | 157 | { |
150 | lan = stndup (language, length - pos); | 158 | lan = stndup (language, length - pos); |
151 | ADDF (EXTRACTOR_METATYPE_LANGUAGE, | 159 | ADDF (EXTRACTOR_METATYPE_LANGUAGE, lan); |
152 | lan); | ||
153 | } | 160 | } |
154 | pos += stnlen (language, length - pos) + 1; | 161 | pos += stnlen (language, length - pos) + 1; |
155 | if (pos + 1 >= length) | 162 | if (pos + 1 >= length) |
@@ -158,8 +165,7 @@ processiTXt (const char *data, | |||
158 | if (stnlen (translated, length - pos) > 0) | 165 | if (stnlen (translated, length - pos) > 0) |
159 | { | 166 | { |
160 | lan = stndup (translated, length - pos); | 167 | lan = stndup (translated, length - pos); |
161 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, | 168 | ADDF (EXTRACTOR_METATYPE_KEYWORDS, lan); |
162 | lan); | ||
163 | } | 169 | } |
164 | pos += stnlen (translated, length - pos) + 1; | 170 | pos += stnlen (translated, length - pos) + 1; |
165 | if (pos >= length) | 171 | if (pos >= length) |
@@ -214,38 +220,44 @@ processiTXt (const char *data, | |||
214 | i++; | 220 | i++; |
215 | } | 221 | } |
216 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); | 222 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); |
217 | FINISH: | 223 | FINISH: |
218 | return ret; | 224 | return ret; |
219 | } | 225 | } |
220 | 226 | ||
221 | 227 | ||
222 | static int | 228 | static int |
223 | processIHDR (const char *data, | 229 | processIHDR (struct EXTRACTOR_PluginList *plugin, |
224 | unsigned int length, | 230 | unsigned int length, |
225 | EXTRACTOR_MetaDataProcessor proc, | 231 | EXTRACTOR_MetaDataProcessor proc, |
226 | void *proc_cls) | 232 | void *proc_cls) |
227 | { | 233 | { |
234 | unsigned char *data; | ||
228 | char tmp[128]; | 235 | char tmp[128]; |
229 | int ret; | 236 | int ret; |
230 | 237 | ||
231 | if (length < 12) | 238 | if (length < 12) |
232 | return 0; | 239 | return 0; |
240 | |||
241 | if (length != pl_read (plugin, &data, length)) | ||
242 | return 1; | ||
243 | |||
233 | ret = 0; | 244 | ret = 0; |
234 | snprintf (tmp, | 245 | snprintf (tmp, |
235 | sizeof(tmp), | 246 | sizeof(tmp), |
236 | "%ux%u", | 247 | "%ux%u", |
237 | htonl (getIntAt (&data[4])), htonl (getIntAt (&data[8]))); | 248 | htonl (getIntAt (data)), htonl (getIntAt (&data[4]))); |
238 | ADD (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, tmp); | 249 | ADD (EXTRACTOR_METATYPE_IMAGE_DIMENSIONS, tmp); |
239 | FINISH: | 250 | FINISH: |
240 | return ret; | 251 | return ret; |
241 | } | 252 | } |
242 | 253 | ||
243 | static int | 254 | static int |
244 | processzTXt (const char *data, | 255 | processzTXt (struct EXTRACTOR_PluginList *plugin, |
245 | unsigned int length, | 256 | unsigned int length, |
246 | EXTRACTOR_MetaDataProcessor proc, | 257 | EXTRACTOR_MetaDataProcessor proc, |
247 | void *proc_cls) | 258 | void *proc_cls) |
248 | { | 259 | { |
260 | unsigned char *data; | ||
249 | char *keyword; | 261 | char *keyword; |
250 | unsigned int off; | 262 | unsigned int off; |
251 | int i; | 263 | int i; |
@@ -254,7 +266,10 @@ processzTXt (const char *data, | |||
254 | int zret; | 266 | int zret; |
255 | int ret; | 267 | int ret; |
256 | 268 | ||
257 | data += 4; | 269 | if (length != pl_read (plugin, &data, length)) |
270 | return 1; | ||
271 | |||
272 | //data += 4; | ||
258 | off = stnlen (data, length) + 1; | 273 | off = stnlen (data, length) + 1; |
259 | if (off >= length) | 274 | if (off >= length) |
260 | return 0; /* failed to find '\0' */ | 275 | return 0; /* failed to find '\0' */ |
@@ -303,16 +318,17 @@ processzTXt (const char *data, | |||
303 | i++; | 318 | i++; |
304 | } | 319 | } |
305 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); | 320 | ADDF (EXTRACTOR_METATYPE_COMMENT, keyword); |
306 | FINISH: | 321 | FINISH: |
307 | return ret; | 322 | return ret; |
308 | } | 323 | } |
309 | 324 | ||
310 | static int | 325 | static int |
311 | processtIME (const char *data, | 326 | processtIME (struct EXTRACTOR_PluginList *plugin, |
312 | unsigned int length, | 327 | unsigned int length, |
313 | EXTRACTOR_MetaDataProcessor proc, | 328 | EXTRACTOR_MetaDataProcessor proc, |
314 | void *proc_cls) | 329 | void *proc_cls) |
315 | { | 330 | { |
331 | unsigned char *data; | ||
316 | unsigned short y; | 332 | unsigned short y; |
317 | unsigned int year; | 333 | unsigned int year; |
318 | unsigned int mo; | 334 | unsigned int mo; |
@@ -325,8 +341,12 @@ processtIME (const char *data, | |||
325 | 341 | ||
326 | if (length != 7) | 342 | if (length != 7) |
327 | return 0; | 343 | return 0; |
344 | |||
345 | if (length != pl_read (plugin, &data, length)) | ||
346 | return 1; | ||
347 | |||
328 | ret = 0; | 348 | ret = 0; |
329 | memcpy (&y, &data[4], sizeof (unsigned short)); | 349 | memcpy (&y, data, sizeof (unsigned short)); |
330 | year = ntohs (y); | 350 | year = ntohs (y); |
331 | mo = (unsigned char) data[6]; | 351 | mo = (unsigned char) data[6]; |
332 | day = (unsigned char) data[7]; | 352 | day = (unsigned char) data[7]; |
@@ -337,7 +357,7 @@ processtIME (const char *data, | |||
337 | sizeof(val), | 357 | sizeof(val), |
338 | "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s); | 358 | "%04u-%02u-%02u %02d:%02d:%02d", year, mo, day, h, m, s); |
339 | ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val); | 359 | ADD (EXTRACTOR_METATYPE_MODIFICATION_DATE, val); |
340 | FINISH: | 360 | FINISH: |
341 | return ret; | 361 | return ret; |
342 | } | 362 | } |
343 | 363 | ||
@@ -345,47 +365,55 @@ processtIME (const char *data, | |||
345 | 365 | ||
346 | 366 | ||
347 | 367 | ||
348 | int | 368 | int |
349 | EXTRACTOR_png_extract (const char *data, | 369 | EXTRACTOR_png_extract_method (struct EXTRACTOR_PluginList *plugin, |
350 | size_t size, | 370 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) |
351 | EXTRACTOR_MetaDataProcessor proc, | ||
352 | void *proc_cls, | ||
353 | const char *options) | ||
354 | { | 371 | { |
355 | const char *pos; | 372 | unsigned char *data; |
356 | const char *end; | ||
357 | unsigned int length; | 373 | unsigned int length; |
374 | int64_t pos; | ||
358 | int ret; | 375 | int ret; |
359 | 376 | ||
360 | if (size < strlen (PNG_HEADER)) | 377 | if (plugin == NULL) |
361 | return 0; | 378 | return 1; |
362 | if (0 != strncmp (data, PNG_HEADER, strlen (PNG_HEADER))) | 379 | |
363 | return 0; | 380 | ret = strlen (PNG_HEADER); |
364 | end = &data[size]; | 381 | |
365 | pos = &data[strlen (PNG_HEADER)]; | 382 | if (ret != pl_read (plugin, &data, ret)) |
383 | return 1; | ||
384 | |||
385 | if (0 != strncmp (data, PNG_HEADER, ret)) | ||
386 | return 1; | ||
387 | |||
366 | ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png"); | 388 | ADD (EXTRACTOR_METATYPE_MIMETYPE, "image/png"); |
367 | ret = 0; | 389 | ret = 0; |
368 | while (ret == 0) | 390 | while (ret == 0) |
369 | { | 391 | { |
370 | if (pos + 12 >= end) | 392 | if (4 != pl_read (plugin, &data, 4)) |
371 | break; | 393 | break; |
372 | length = htonl (getIntAt (pos)); | 394 | length = htonl (getIntAt (data)); |
373 | pos += 4; | ||
374 | /* printf("Length: %u, pos %u\n", length, pos - data); */ | 395 | /* printf("Length: %u, pos %u\n", length, pos - data); */ |
375 | if ((pos + 4 + length + 4 > end) || (pos + 4 + length + 4 < pos + 8)) | 396 | if (4 != pl_read (plugin, &data, 4)) |
397 | break; | ||
398 | pos = pl_get_pos (plugin); | ||
399 | if (pos <= 0) | ||
400 | break; | ||
401 | pos += length + 4; /* Chunk type, data, crc */ | ||
402 | if (0 == strncmp (data, "IHDR", 4)) | ||
403 | ret = processIHDR (plugin, length, proc, proc_cls); | ||
404 | if (0 == strncmp (data, "iTXt", 4)) | ||
405 | ret = processiTXt (plugin, length, proc, proc_cls); | ||
406 | if (0 == strncmp (data, "tEXt", 4)) | ||
407 | ret = processtEXt (plugin, length, proc, proc_cls); | ||
408 | if (0 == strncmp (data, "zTXt", 4)) | ||
409 | ret = processzTXt (plugin, length, proc, proc_cls); | ||
410 | if (0 == strncmp (data, "tIME", 4)) | ||
411 | ret = processtIME (plugin, length, proc, proc_cls); | ||
412 | if (ret != 0) | ||
413 | break; | ||
414 | if (pos != pl_seek (plugin, pos, SEEK_SET)) | ||
376 | break; | 415 | break; |
377 | if (0 == strncmp (pos, "IHDR", 4)) | ||
378 | ret = processIHDR (pos, length, proc, proc_cls); | ||
379 | if (0 == strncmp (pos, "iTXt", 4)) | ||
380 | ret = processiTXt (pos, length, proc, proc_cls); | ||
381 | if (0 == strncmp (pos, "tEXt", 4)) | ||
382 | ret = processtEXt (pos, length, proc, proc_cls); | ||
383 | if (0 == strncmp (pos, "zTXt", 4)) | ||
384 | ret = processzTXt (pos, length, proc, proc_cls); | ||
385 | if (0 == strncmp (pos, "tIME", 4)) | ||
386 | ret = processtIME (pos, length, proc, proc_cls); | ||
387 | pos += 4 + length + 4; /* Chunk type, data, crc */ | ||
388 | } | 416 | } |
389 | FINISH: | 417 | FINISH: |
390 | return ret; | 418 | return 1; |
391 | } | 419 | } |