aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/include/extractor.h2
-rw-r--r--src/plugins/flac_extractor.c93
3 files changed, 51 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index 313f54b..43ad6eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
1Mon Oct 9 15:33:01 CEST 2017
2 Fix NPE in FLAC plugin found by Leon Zhao. -CG
3
1Mon Oct 9 15:30:01 CEST 2017 4Mon Oct 9 15:30:01 CEST 2017
2 Fix SIGFPE in WAV plugin found by Leon Zhao. -CG 5 Fix SIGFPE in WAV plugin found by Leon Zhao. -CG
3 6
diff --git a/src/include/extractor.h b/src/include/extractor.h
index 099e13a..38fa8fa 100644
--- a/src/include/extractor.h
+++ b/src/include/extractor.h
@@ -35,7 +35,7 @@ extern "C" {
35 * 0.2.6-1 => 0x00020601 35 * 0.2.6-1 => 0x00020601
36 * 4.5.2-0 => 0x04050200 36 * 4.5.2-0 => 0x04050200
37 */ 37 */
38#define EXTRACTOR_VERSION 0x01030002 38#define EXTRACTOR_VERSION 0x01030003
39 39
40#include <stdio.h> 40#include <stdio.h>
41 41
diff --git a/src/plugins/flac_extractor.c b/src/plugins/flac_extractor.c
index 3e88516..0136fc4 100644
--- a/src/plugins/flac_extractor.c
+++ b/src/plugins/flac_extractor.c
@@ -46,12 +46,12 @@
46 * @return status code (error, end-of-file or success) 46 * @return status code (error, end-of-file or success)
47 */ 47 */
48static FLAC__StreamDecoderReadStatus 48static FLAC__StreamDecoderReadStatus
49flac_read (const FLAC__StreamDecoder *decoder, 49flac_read (const FLAC__StreamDecoder *decoder,
50 FLAC__byte buffer[], 50 FLAC__byte buffer[],
51 size_t *bytes, 51 size_t *bytes,
52 void *client_data) 52 void *client_data)
53{ 53{
54 struct EXTRACTOR_ExtractContext *ec = client_data; 54 struct EXTRACTOR_ExtractContext *ec = client_data;
55 void *data; 55 void *data;
56 ssize_t ret; 56 ssize_t ret;
57 57
@@ -81,7 +81,7 @@ flac_read (const FLAC__StreamDecoder *decoder,
81 * @param client_data the 'struct EXTRACTOR_ExtractContext' 81 * @param client_data the 'struct EXTRACTOR_ExtractContext'
82 * @return status code (error or success) 82 * @return status code (error or success)
83 */ 83 */
84static FLAC__StreamDecoderSeekStatus 84static FLAC__StreamDecoderSeekStatus
85flac_seek (const FLAC__StreamDecoder *decoder, 85flac_seek (const FLAC__StreamDecoder *decoder,
86 FLAC__uint64 absolute_byte_offset, 86 FLAC__uint64 absolute_byte_offset,
87 void *client_data) 87 void *client_data)
@@ -103,9 +103,9 @@ flac_seek (const FLAC__StreamDecoder *decoder,
103 * @param client_data the 'struct EXTRACTOR_ExtractContext' 103 * @param client_data the 'struct EXTRACTOR_ExtractContext'
104 * @return status code (error or success) 104 * @return status code (error or success)
105 */ 105 */
106static FLAC__StreamDecoderTellStatus 106static FLAC__StreamDecoderTellStatus
107flac_tell (const FLAC__StreamDecoder *decoder, 107flac_tell (const FLAC__StreamDecoder *decoder,
108 FLAC__uint64 *absolute_byte_offset, 108 FLAC__uint64 *absolute_byte_offset,
109 void *client_data) 109 void *client_data)
110{ 110{
111 struct EXTRACTOR_ExtractContext *ec = client_data; 111 struct EXTRACTOR_ExtractContext *ec = client_data;
@@ -113,7 +113,7 @@ flac_tell (const FLAC__StreamDecoder *decoder,
113 *absolute_byte_offset = ec->seek (ec->cls, 113 *absolute_byte_offset = ec->seek (ec->cls,
114 0, 114 0,
115 SEEK_CUR); 115 SEEK_CUR);
116 return FLAC__STREAM_DECODER_TELL_STATUS_OK; 116 return FLAC__STREAM_DECODER_TELL_STATUS_OK;
117} 117}
118 118
119 119
@@ -125,13 +125,13 @@ flac_tell (const FLAC__StreamDecoder *decoder,
125 * @param client_data the 'struct EXTRACTOR_ExtractContext' 125 * @param client_data the 'struct EXTRACTOR_ExtractContext'
126 * @return true at EOF, false if not 126 * @return true at EOF, false if not
127 */ 127 */
128static FLAC__StreamDecoderLengthStatus 128static FLAC__StreamDecoderLengthStatus
129flac_length (const FLAC__StreamDecoder *decoder, 129flac_length (const FLAC__StreamDecoder *decoder,
130 FLAC__uint64 *stream_length, 130 FLAC__uint64 *stream_length,
131 void *client_data) 131 void *client_data)
132{ 132{
133 struct EXTRACTOR_ExtractContext *ec = client_data; 133 struct EXTRACTOR_ExtractContext *ec = client_data;
134 134
135 *stream_length = ec->get_size (ec->cls); 135 *stream_length = ec->get_size (ec->cls);
136 return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; 136 return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
137} 137}
@@ -146,8 +146,8 @@ flac_length (const FLAC__StreamDecoder *decoder,
146 * @return true at EOF, false if not 146 * @return true at EOF, false if not
147 */ 147 */
148static FLAC__bool 148static FLAC__bool
149flac_eof (const FLAC__StreamDecoder *decoder, 149flac_eof (const FLAC__StreamDecoder *decoder,
150 void *client_data) 150 void *client_data)
151{ 151{
152 struct EXTRACTOR_ExtractContext *ec = client_data; 152 struct EXTRACTOR_ExtractContext *ec = client_data;
153 uint64_t size; 153 uint64_t size;
@@ -175,9 +175,9 @@ flac_eof (const FLAC__StreamDecoder *decoder,
175 */ 175 */
176static FLAC__StreamDecoderWriteStatus 176static FLAC__StreamDecoderWriteStatus
177flac_write (const FLAC__StreamDecoder *decoder, 177flac_write (const FLAC__StreamDecoder *decoder,
178 const FLAC__Frame *frame, 178 const FLAC__Frame *frame,
179 const FLAC__int32 *const buffer[], 179 const FLAC__int32 *const buffer[],
180 void *client_data) 180 void *client_data)
181{ 181{
182 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; 182 return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
183} 183}
@@ -217,7 +217,7 @@ static struct Matches tmap[] = {
217 {"GENRE", EXTRACTOR_METATYPE_GENRE}, 217 {"GENRE", EXTRACTOR_METATYPE_GENRE},
218 {"DATE", EXTRACTOR_METATYPE_CREATION_DATE}, 218 {"DATE", EXTRACTOR_METATYPE_CREATION_DATE},
219 {"LOCATION", EXTRACTOR_METATYPE_LOCATION_SUBLOCATION}, 219 {"LOCATION", EXTRACTOR_METATYPE_LOCATION_SUBLOCATION},
220 {"CONTACT", EXTRACTOR_METATYPE_CONTACT_INFORMATION}, 220 {"CONTACT", EXTRACTOR_METATYPE_CONTACT_INFORMATION},
221 {"TRACKNUMBER", EXTRACTOR_METATYPE_TRACK_NUMBER}, 221 {"TRACKNUMBER", EXTRACTOR_METATYPE_TRACK_NUMBER},
222 {"ISRC", EXTRACTOR_METATYPE_ISRC}, 222 {"ISRC", EXTRACTOR_METATYPE_ISRC},
223 {NULL, 0} 223 {NULL, 0}
@@ -241,7 +241,7 @@ static struct Matches tmap[] = {
241 * @return NULL on error, otherwise 0-terminated version of 's' 241 * @return NULL on error, otherwise 0-terminated version of 's'
242 */ 242 */
243static char * 243static char *
244xstrndup (const char *s, 244xstrndup (const char *s,
245 size_t n) 245 size_t n)
246{ 246{
247 char * d; 247 char * d;
@@ -281,7 +281,7 @@ check (const char *type,
281 type, 281 type,
282 type_length)) ) 282 type_length)) )
283 continue; 283 continue;
284 if (NULL == 284 if (NULL ==
285 (tmp = xstrndup (value, 285 (tmp = xstrndup (value,
286 value_length))) 286 value_length)))
287 continue; 287 continue;
@@ -299,10 +299,10 @@ check (const char *type,
299 * @param metadata meta data that was found 299 * @param metadata meta data that was found
300 * @param client_data the 'struct EXTRACTOR_ExtractContext' 300 * @param client_data the 'struct EXTRACTOR_ExtractContext'
301 */ 301 */
302static void 302static void
303flac_metadata (const FLAC__StreamDecoder *decoder, 303flac_metadata (const FLAC__StreamDecoder *decoder,
304 const FLAC__StreamMetadata *metadata, 304 const FLAC__StreamMetadata *metadata,
305 void *client_data) 305 void *client_data)
306{ 306{
307 struct EXTRACTOR_ExtractContext *ec = client_data; 307 struct EXTRACTOR_ExtractContext *ec = client_data;
308 enum EXTRACTOR_MetaType type; 308 enum EXTRACTOR_MetaType type;
@@ -313,32 +313,34 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
313 unsigned int len; 313 unsigned int len;
314 unsigned int ilen; 314 unsigned int ilen;
315 char buf[128]; 315 char buf[128];
316 316
317 switch (metadata->type) 317 switch (metadata->type)
318 { 318 {
319 case FLAC__METADATA_TYPE_STREAMINFO: 319 case FLAC__METADATA_TYPE_STREAMINFO:
320 { 320 {
321 snprintf (buf, sizeof (buf), 321 snprintf (buf, sizeof (buf),
322 _("%u Hz, %u channels"), 322 _("%u Hz, %u channels"),
323 metadata->data.stream_info.sample_rate, 323 metadata->data.stream_info.sample_rate,
324 metadata->data.stream_info.channels); 324 metadata->data.stream_info.channels);
325 ADD (EXTRACTOR_METATYPE_RESOURCE_TYPE, buf); 325 ADD (EXTRACTOR_METATYPE_RESOURCE_TYPE, buf);
326 break; 326 break;
327 } 327 }
328 case FLAC__METADATA_TYPE_APPLICATION: 328 case FLAC__METADATA_TYPE_APPLICATION:
329 /* FIXME: could find out generator application here: 329 /* FIXME: could find out generator application here:
330 http://flac.sourceforge.net/api/structFLAC____StreamMetadata__Application.html and 330 http://flac.sourceforge.net/api/structFLAC____StreamMetadata__Application.html and
331 http://flac.sourceforge.net/id.html 331 http://flac.sourceforge.net/id.html
332 */ 332 */
333 break; 333 break;
334 case FLAC__METADATA_TYPE_VORBIS_COMMENT: 334 case FLAC__METADATA_TYPE_VORBIS_COMMENT:
335 { 335 {
336 vc = &metadata->data.vorbis_comment; 336 vc = &metadata->data.vorbis_comment;
337 count = vc->num_comments; 337 count = vc->num_comments;
338 while (count-- > 0) 338 while (count-- > 0)
339 { 339 {
340 entry = &vc->comments[count]; 340 entry = &vc->comments[count];
341 eq = (const char*) entry->entry; 341 eq = (const char*) entry->entry;
342 if (NULL == eq)
343 break;
342 len = entry->length; 344 len = entry->length;
343 ilen = 0; 345 ilen = 0;
344 while ( ('=' != *eq) && ('\0' != *eq) && 346 while ( ('=' != *eq) && ('\0' != *eq) &&
@@ -355,7 +357,7 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
355 ilen, 357 ilen,
356 eq, 358 eq,
357 len - ilen, 359 len - ilen,
358 ec); 360 ec);
359 } 361 }
360 break; 362 break;
361 } 363 }
@@ -366,11 +368,11 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
366 case FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER: 368 case FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER:
367 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD: 369 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD:
368 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON: 370 case FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON:
369 type = EXTRACTOR_METATYPE_THUMBNAIL; 371 type = EXTRACTOR_METATYPE_THUMBNAIL;
370 break; 372 break;
371 case FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER: 373 case FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER:
372 case FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER: 374 case FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER:
373 type = EXTRACTOR_METATYPE_COVER_PICTURE; 375 type = EXTRACTOR_METATYPE_COVER_PICTURE;
374 break; 376 break;
375 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST: 377 case FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST:
376 case FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST: 378 case FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST:
@@ -378,13 +380,13 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
378 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND: 380 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND:
379 case FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER: 381 case FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER:
380 case FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST: 382 case FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST:
381 type = EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE; 383 type = EXTRACTOR_METATYPE_CONTRIBUTOR_PICTURE;
382 break; 384 break;
383 case FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION: 385 case FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION:
384 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING: 386 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING:
385 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE: 387 case FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE:
386 case FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE: 388 case FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE:
387 type = EXTRACTOR_METATYPE_EVENT_PICTURE; 389 type = EXTRACTOR_METATYPE_EVENT_PICTURE;
388 break; 390 break;
389 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE: 391 case FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE:
390 case FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE: 392 case FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE:
@@ -396,10 +398,10 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
396 case FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION: 398 case FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION:
397 default: 399 default:
398 type = EXTRACTOR_METATYPE_PICTURE; 400 type = EXTRACTOR_METATYPE_PICTURE;
399 break; 401 break;
400 } 402 }
401 ec->proc (ec->cls, 403 ec->proc (ec->cls,
402 "flac", 404 "flac",
403 type, 405 type,
404 EXTRACTOR_METAFORMAT_BINARY, 406 EXTRACTOR_METAFORMAT_BINARY,
405 metadata->data.picture.mime_type, 407 metadata->data.picture.mime_type,
@@ -413,7 +415,7 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
413 case FLAC__METADATA_TYPE_UNDEFINED: 415 case FLAC__METADATA_TYPE_UNDEFINED:
414 break; 416 break;
415 } 417 }
416} 418}
417 419
418 420
419/** 421/**
@@ -424,9 +426,9 @@ flac_metadata (const FLAC__StreamDecoder *decoder,
424 * @param client_data our 'struct EXTRACTOR_ExtractContext' 426 * @param client_data our 'struct EXTRACTOR_ExtractContext'
425 */ 427 */
426static void 428static void
427flac_error (const FLAC__StreamDecoder *decoder, 429flac_error (const FLAC__StreamDecoder *decoder,
428 FLAC__StreamDecoderErrorStatus status, 430 FLAC__StreamDecoderErrorStatus status,
429 void *client_data) 431 void *client_data)
430{ 432{
431 /* ignore errors */ 433 /* ignore errors */
432} 434}
@@ -437,7 +439,7 @@ flac_error (const FLAC__StreamDecoder *decoder,
437 * 439 *
438 * @param ec extraction context provided to the plugin 440 * @param ec extraction context provided to the plugin
439 */ 441 */
440void 442void
441EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec) 443EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
442{ 444{
443 FLAC__StreamDecoder * decoder; 445 FLAC__StreamDecoder * decoder;
@@ -448,7 +450,7 @@ EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
448 FLAC__stream_decoder_set_metadata_ignore_all (decoder); 450 FLAC__stream_decoder_set_metadata_ignore_all (decoder);
449 if (false == FLAC__stream_decoder_set_metadata_respond_all (decoder)) 451 if (false == FLAC__stream_decoder_set_metadata_respond_all (decoder))
450 { 452 {
451 FLAC__stream_decoder_delete (decoder); 453 FLAC__stream_decoder_delete (decoder);
452 return; 454 return;
453 } 455 }
454 if (FLAC__STREAM_DECODER_INIT_STATUS_OK != 456 if (FLAC__STREAM_DECODER_INIT_STATUS_OK !=
@@ -463,17 +465,17 @@ EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
463 &flac_error, 465 &flac_error,
464 ec)) 466 ec))
465 { 467 {
466 FLAC__stream_decoder_delete (decoder); 468 FLAC__stream_decoder_delete (decoder);
467 return; 469 return;
468 } 470 }
469 if (FLAC__STREAM_DECODER_SEARCH_FOR_METADATA != FLAC__stream_decoder_get_state(decoder)) 471 if (FLAC__STREAM_DECODER_SEARCH_FOR_METADATA != FLAC__stream_decoder_get_state(decoder))
470 { 472 {
471 FLAC__stream_decoder_delete (decoder); 473 FLAC__stream_decoder_delete (decoder);
472 return; 474 return;
473 } 475 }
474 if (! FLAC__stream_decoder_process_until_end_of_metadata(decoder)) 476 if (! FLAC__stream_decoder_process_until_end_of_metadata(decoder))
475 { 477 {
476 FLAC__stream_decoder_delete (decoder); 478 FLAC__stream_decoder_delete (decoder);
477 return; 479 return;
478 } 480 }
479 switch (FLAC__stream_decoder_get_state (decoder)) 481 switch (FLAC__stream_decoder_get_state (decoder))
@@ -487,9 +489,8 @@ EXTRACTOR_flac_extract_method (struct EXTRACTOR_ExtractContext *ec)
487 /* not so sure... */ 489 /* not so sure... */
488 break; 490 break;
489 } 491 }
490 FLAC__stream_decoder_finish (decoder); 492 FLAC__stream_decoder_finish (decoder);
491 FLAC__stream_decoder_delete (decoder); 493 FLAC__stream_decoder_delete (decoder);
492} 494}
493 495
494/* end of flac_extractor.c */ 496/* end of flac_extractor.c */
495