mp3utils.c: check for false positives if id3v1 isn't at file's end.
authorOzkan Sezer <sezeroz@gmail.com>
Thu, 26 Dec 2019 17:25:50 +0300
changeset 1123d40dacdd4ab1
parent 1122 6bf0bc6d510c
child 1127 d2686bcfcba2
mp3utils.c: check for false positives if id3v1 isn't at file's end.
src/codecs/mp3utils.c
     1.1 --- a/src/codecs/mp3utils.c	Mon Dec 23 14:05:50 2019 +0300
     1.2 +++ b/src/codecs/mp3utils.c	Thu Dec 26 17:25:50 2019 +0300
     1.3 @@ -62,7 +62,7 @@
     1.4  
     1.5  static SDL_INLINE SDL_bool is_id3v1(const unsigned char *data, long length) {
     1.6      /* http://id3.org/ID3v1 :  3 bytes "TAG" identifier and 125 bytes tag data */
     1.7 -    if (length < 3 || SDL_memcmp(data,"TAG",3) != 0) {
     1.8 +    if (length < 128 || SDL_memcmp(data,"TAG",3) != 0) {
     1.9          return SDL_FALSE;
    1.10      }
    1.11      return SDL_TRUE;
    1.12 @@ -274,12 +274,19 @@
    1.13      return len + 256; /* header is present. */
    1.14  }
    1.15  
    1.16 -static int probe_id3v1(struct mp3file_t *fil, unsigned char *buf) {
    1.17 +static int probe_id3v1(struct mp3file_t *fil, unsigned char *buf, int atend) {
    1.18      if (fil->length >= 128) {
    1.19          MP3_RWseek(fil, -128, RW_SEEK_END);
    1.20          if (MP3_RWread(fil, buf, 1, 128) != 128)
    1.21              return -1;
    1.22          if (is_id3v1(buf, 128)) {
    1.23 +            if (!atend) { /* possible false positive? */
    1.24 +                if (is_musicmatch(buf + 128 - 48, 48) ||
    1.25 +                    is_apetag    (buf + 128 - 32, 32) ||
    1.26 +                    is_lyrics3tag(buf + 128 - 15, 15)) {
    1.27 +                    return 0;
    1.28 +                }
    1.29 +            }
    1.30              fil->length -= 128;
    1.31              return 1;
    1.32              /* FIXME: handle possible double-ID3v1 tags?? */
    1.33 @@ -368,7 +375,7 @@
    1.34      if (is_id3v2(buf, readsize)) {
    1.35          len = get_id3v2_len(buf, (long)readsize);
    1.36          if (len >= fil->length) goto fail;
    1.37 -        if (! keep_id3v2) {
    1.38 +        if (!keep_id3v2) {
    1.39              fil->start  += len;
    1.40              fil->length -= len;
    1.41          }
    1.42 @@ -388,7 +395,7 @@
    1.43          goto fail;
    1.44      }
    1.45      /* ID3v1 tag is at the end */
    1.46 -    if ((c_id3 = probe_id3v1(fil, buf)) < 0) {
    1.47 +    if ((c_id3 = probe_id3v1(fil, buf, !c_mm)) < 0) {
    1.48          goto fail;
    1.49      }
    1.50      /* we do not know the order of ape or lyrics3