Skip to content
Permalink
Browse files

mp3utils.c: check for false positives if id3v1 isn't at file's end.

  • Loading branch information
sezero committed Dec 26, 2019
1 parent f191806 commit 647d093f20e0d6332ee0860aafbcc8bef0d33802
Showing with 10 additions and 3 deletions.
  1. +10 −3 mp3utils.c
@@ -62,7 +62,7 @@ int MP3_RWseek(struct mp3file_t *fil, int offset, int whence) {

static __inline__ SDL_bool is_id3v1(const unsigned char *data, int length) {
/* http://id3.org/ID3v1 : 3 bytes "TAG" identifier and 125 bytes tag data */
if (length < 3 || SDL_memcmp(data,"TAG",3) != 0) {
if (length < 128 || SDL_memcmp(data,"TAG",3) != 0) {
return SDL_FALSE;
}
return SDL_TRUE;
@@ -274,12 +274,19 @@ static int get_musicmatch_len(struct mp3file_t *m) {
return len + 256; /* header is present. */
}

static int probe_id3v1(struct mp3file_t *fil, unsigned char *buf) {
static int probe_id3v1(struct mp3file_t *fil, unsigned char *buf, int atend) {
if (fil->length >= 128) {
MP3_RWseek(fil, -128, RW_SEEK_END);
if (MP3_RWread(fil, buf, 1, 128) != 128)
return -1;
if (is_id3v1(buf, 128)) {
if (!atend) { /* possible false positive? */
if (is_musicmatch(buf + 128 - 48, 48) ||
is_apetag (buf + 128 - 32, 32) ||
is_lyrics3tag(buf + 128 - 15, 15)) {
return 0;
}
}
fil->length -= 128;
return 1;
/* FIXME: handle possible double-ID3v1 tags?? */
@@ -386,7 +393,7 @@ int mp3_skiptags(struct mp3file_t *fil)
goto fail;
}
/* ID3v1 tag is at the end */
if ((c_id3 = probe_id3v1(fil, buf)) < 0) {
if ((c_id3 = probe_id3v1(fil, buf, !c_mm)) < 0) {
goto fail;
}
/* we do not know the order of ape or lyrics3

0 comments on commit 647d093

Please sign in to comment.