mp3utils.c: removed unnecessary file rewind calls in tag detection code.
1.1 --- a/src/codecs/mp3utils.c Tue Dec 10 17:55:03 2019 +0300
1.2 +++ b/src/codecs/mp3utils.c Wed Dec 11 00:50:02 2019 +0300
1.3 @@ -149,7 +149,6 @@
1.4 len = (m->length > 5109)? 5109 : (long)m->length;
1.5 MP3_RWseek(m, -len, RW_SEEK_END);
1.6 MP3_RWread(m, buf, 1, (len -= 9)); /* exclude footer */
1.7 - MP3_RWseek(m, 0, RW_SEEK_SET);
1.8 /* strstr() won't work here. */
1.9 for (i = len - 11, p = buf; i >= 0; --i, ++p) {
1.10 if (SDL_memcmp(p, "LYRICSBEGIN", 11) == 0)
1.11 @@ -174,52 +173,49 @@
1.12 {
1.13 unsigned char buf[128];
1.14 long len; size_t readsize;
1.15 + int rc = -1;
1.16
1.17 readsize = MP3_RWread(fil, buf, 1, 128);
1.18 - if (!readsize) return -1;
1.19 + if (!readsize) goto fail;
1.20
1.21 /* ID3v2 tag is at the start */
1.22 if (is_id3v2(buf, readsize)) {
1.23 len = get_id3v2_len(buf, (long)readsize);
1.24 - if (len >= fil->length) return -1;
1.25 + if (len >= fil->length) goto fail;
1.26 fil->start += len;
1.27 fil->length -= len;
1.28 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.29 }
1.30 /* APE tag _might_ be at the start (discouraged
1.31 * but not forbidden, either.) read the header. */
1.32 else if (is_apetag(buf, readsize)) {
1.33 len = get_ape_len(buf);
1.34 - if (len >= fil->length) return -1;
1.35 + if (len >= fil->length) goto fail;
1.36 fil->start += len;
1.37 fil->length -= len;
1.38 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.39 }
1.40
1.41 /* ID3v1 tag is at the end */
1.42 - if (fil->length < 128) goto ape;
1.43 - MP3_RWseek(fil, -128, RW_SEEK_END);
1.44 - readsize = MP3_RWread(fil, buf, 1, 128);
1.45 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.46 - if (readsize != 128) return -1;
1.47 - if (is_id3v1(buf, 128)) {
1.48 - fil->length -= 128;
1.49 -
1.50 - /* FIXME: handle possible double-ID3v1 tags?? */
1.51 + if (fil->length >= 128) {
1.52 + MP3_RWseek(fil, -128, RW_SEEK_END);
1.53 + readsize = MP3_RWread(fil, buf, 1, 128);
1.54 + if (readsize != 128) goto fail;
1.55 + if (is_id3v1(buf, 128)) {
1.56 + fil->length -= 128;
1.57 + /* FIXME: handle possible double-ID3v1 tags?? */
1.58 + }
1.59 }
1.60
1.61 /* do we know whether ape or lyrics3 is the first?
1.62 * well, we don't: we need to handle that later... */
1.63
1.64 - ape: /* APE tag may be at the end: read the footer */
1.65 + /* APE tag may be at the end: read the footer */
1.66 if (fil->length >= 32) {
1.67 MP3_RWseek(fil, -32, RW_SEEK_END);
1.68 readsize = MP3_RWread(fil, buf, 1, 32);
1.69 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.70 - if (readsize != 32) return -1;
1.71 + if (readsize != 32) goto fail;
1.72 if (is_apetag(buf, 32)) {
1.73 len = get_ape_len(buf);
1.74 - if (len >= fil->length) return -1;
1.75 + if (len >= fil->length) goto fail;
1.76 fil->length -= len;
1.77 }
1.78 }
1.79 @@ -227,28 +223,29 @@
1.80 if (fil->length >= 15) {
1.81 MP3_RWseek(fil, -15, RW_SEEK_END);
1.82 readsize = MP3_RWread(fil, buf, 1, 15);
1.83 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.84 - if (readsize != 15) return -1;
1.85 + if (readsize != 15) goto fail;
1.86 len = is_lyrics3tag(buf, 15);
1.87 if (len == 2) {
1.88 len = get_lyrics3v2_len(buf, 6);
1.89 - if (len >= fil->length) return -1;
1.90 - if (len < 15) return -1;
1.91 + if (len >= fil->length) goto fail;
1.92 + if (len < 15) goto fail;
1.93 MP3_RWseek(fil, -len, RW_SEEK_END);
1.94 readsize = MP3_RWread(fil, buf, 1, 11);
1.95 - MP3_RWseek(fil, 0, RW_SEEK_SET);
1.96 - if (readsize != 11) return -1;
1.97 - if (!verify_lyrics3v2(buf, 11)) return -1;
1.98 + if (readsize != 11) goto fail;
1.99 + if (!verify_lyrics3v2(buf, 11)) goto fail;
1.100 fil->length -= len;
1.101 }
1.102 else if (len == 1) {
1.103 len = get_lyrics3v1_len(fil);
1.104 - if (len < 0) return -1;
1.105 + if (len < 0) goto fail;
1.106 fil->length -= len;
1.107 }
1.108 }
1.109
1.110 - return (fil->length > 0)? 0: -1;
1.111 + rc = 0;
1.112 + fail:
1.113 + MP3_RWseek(fil, 0, RW_SEEK_SET);
1.114 + return (fil->length > 0)? rc : -1;
1.115 }
1.116 #endif /* MUSIC_MP3_????? */
1.117
2.1 --- a/src/codecs/music_mad.c Tue Dec 10 17:55:03 2019 +0300
2.2 +++ b/src/codecs/music_mad.c Wed Dec 11 00:50:02 2019 +0300
2.3 @@ -169,7 +169,7 @@
2.4 music->mp3file.length = SDL_RWsize(src);
2.5 if (mp3_skiptags(&music->mp3file) < 0) {
2.6 SDL_free(music);
2.7 - Mix_SetError("music_mad: corrupt mp3 file.");
2.8 + Mix_SetError("music_mad: corrupt mp3 file (bad tags.)");
2.9 return NULL;
2.10 }
2.11