ref: 5d0ac2030244b33bf12512267fe62ffe831bf105
parent: b982c4c784095dccb77f57169416e02a0cd9c81d
author: Thomas Daede <daede003@umn.edu>
date: Fri Jan 21 02:03:46 EST 2022
Allow FLAC files with ID3 tags to pass the ID check. Signed-off-by: Mark Harris <mark.hsj@gmail.com>
--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -114,7 +114,7 @@
input_format formats[] = { {wav_id, 12, wav_open, wav_close, "wav", N_("WAV file reader")}, {aiff_id, 12, aiff_open, wav_close, "aiff", N_("AIFF/AIFC file reader")},- {flac_id, 4, flac_open, flac_close, "flac", N_("FLAC file reader")},+ {flac_id, 0x10000, flac_open, flac_close, "flac", N_("FLAC file reader")}, {oggflac_id, 33, flac_open, flac_close, "ogg", N_("Ogg FLAC file reader")}, {NULL, 0, NULL, NULL, NULL, NULL}};
@@ -138,11 +138,9 @@
if (size > buf_filled)
{buf_filled += (int)fread(buf+buf_filled, 1, buf_size-buf_filled, in);
- if (buf_filled < size)
- { /* File truncated */- j++;
- continue;
- }
+ /* We still check a truncated read aginast the id_func
+ * in order to support very small FLAC files but still be able to
+ * read past an ID3 header. */
}
if (formats[j].id_func(buf, buf_filled))
--- a/src/flac.c
+++ b/src/flac.c
@@ -290,10 +290,23 @@
{/*Something screwed up.*/
if(len<4)return 0;
+ /*Normal FLAC.*/
+ if(!memcmp(buf,"fLaC",4))return 1;
+ if(!memcmp(buf,"ID3",3)){+ int i;
+ int id3_len = 0;
+ for(i=0;i<4;i++) {+ if(buf[6+i]&0x80)return 0;
+ id3_len<<=7;
+ id3_len|=buf[6+i];
+ }
+ id3_len+=10;
+ if(len<id3_len+4)return 0;
+ /*FLAC with ID3 tag.*/
+ if(!memcmp(&buf[id3_len],"fLaC",4))return 1;
+ }
/*Not FLAC.*/
- if(memcmp(buf,"fLaC",4))return 0;
- /*Looks like FLAC.*/
- return 1;
+ return 0;
}
int oggflac_id(unsigned char *buf,int len)
--
⑨