mp3utils.c: check for false positives if id3v1 isn't at file's end. SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Thu, 26 Dec 2019 17:28:50 +0300
branchSDL-1.2
changeset 1124a606a79a3b9f
parent 1110 0d4f21a5b678
child 1125 cf41cf196597
mp3utils.c: check for false positives if id3v1 isn't at file's end.
mp3utils.c
     1.1 --- a/mp3utils.c	Sun Dec 22 01:56:31 2019 +0300
     1.2 +++ b/mp3utils.c	Thu Dec 26 17:28:50 2019 +0300
     1.3 @@ -62,7 +62,7 @@
     1.4  
     1.5  static __inline__ SDL_bool is_id3v1(const unsigned char *data, int 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 @@ -386,7 +393,7 @@
    1.34          goto fail;
    1.35      }
    1.36      /* ID3v1 tag is at the end */
    1.37 -    if ((c_id3 = probe_id3v1(fil, buf)) < 0) {
    1.38 +    if ((c_id3 = probe_id3v1(fil, buf, !c_mm)) < 0) {
    1.39          goto fail;
    1.40      }
    1.41      /* we do not know the order of ape or lyrics3