First draft of the libosl patch series.
[paraslash.git] / mp3_afh.c
index 8eec436..2d18d5e 100644 (file)
--- a/mp3_afh.c
+++ b/mp3_afh.c
@@ -395,7 +395,7 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
                struct afh_info *afhi)
 {
        uint64_t freq_sum = 0, br_sum = 0;
-       int ret, len = 0, old_br = -1, vbr = 0;
+       int fl = 0, ret, len = 0, old_br = -1, vbr = 0;
        struct timeval total_time = {0, 0};
        unsigned chunk_table_size = 1000; /* gets increased on demand */
        off_t fpos = 0;
@@ -406,12 +406,20 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
        afhi->chunk_table = para_malloc(chunk_table_size * sizeof(uint32_t));
        taginfo = mp3_get_id3(map, numbytes, fd);
        while (1) {
-               int freq, br, fl;
+               int freq, br;
                struct timeval tmp, cct; /* current chunk time */
                fpos += len;
                len = find_valid_start(map, numbytes, &fpos, &header);
-               if (len <= 0)
+               if (len <= 0) {
+                       size_t end;
+                       ret = -E_MP3_INFO;
+                       if (!afhi->chunks_total)
+                               goto err_out;
+                       end = afhi->chunk_table[afhi->chunks_total - 1] + fl;
+                       afhi->chunk_table[afhi->chunks_total]
+                               = PARA_MIN(end, numbytes);
                        break;
+               }
                ret = header_frequency(&header);
                if (ret < 0)
                        continue;
@@ -443,9 +451,8 @@ static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
                old_br = br;
        }
        ret = -E_MP3_INFO;
-       if (!afhi->chunks_total || !freq_sum || !br_sum)
+       if (!freq_sum || !br_sum)
                goto err_out;
-       afhi->chunk_table[afhi->chunks_total] = numbytes - 1;
        afhi->bitrate = br_sum / afhi->chunks_total;
        afhi->frequency = freq_sum / afhi->chunks_total;
        afhi->channels = header_channels(&header);