shithub: mp3dec

Download patch

ref: 55da78cbeea5fb6757f8df672567714e1e8ca3e9
parent: e46488c87ede450d9f2d12b6d1d67d6d963f6986
author: lieff <lieff@users.noreply.github.com>
date: Wed Mar 4 19:43:31 EST 2020

mp3dec_ex: small mp3dec_detect corrections + coverage test

--- a/minimp3_ex.h
+++ b/minimp3_ex.h
@@ -239,9 +239,9 @@
         filled = io->read(buf, MINIMP3_ID3_DETECT_SIZE, io->read_data);
         if (filled > MINIMP3_ID3_DETECT_SIZE)
             return MP3D_E_IOERROR;
-        if (MINIMP3_ID3_DETECT_SIZE != filled)
-            return MP3D_E_USER;
     }
+    if (filled < MINIMP3_ID3_DETECT_SIZE)
+        return MP3D_E_USER; /* too small, can't be mp3/mpa */
     if (mp3dec_skip_id3v2(buf, filled))
         return 0; /* id3v2 tag is enough evidence */
     if (io)
@@ -259,7 +259,7 @@
             filled = MINIMP3_BUF_SIZE;
     }
     int free_format_bytes, frame_size;
-    mp3d_find_frame(buf, MINIMP3_MIN(filled, (size_t)INT_MAX), &free_format_bytes, &frame_size);
+    mp3d_find_frame(buf, filled, &free_format_bytes, &frame_size);
     if (frame_size)
         return 0; /* MAX_FRAME_SYNC_MATCHES consecutive frames found */
     return MP3D_E_USER;
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -452,6 +452,11 @@
 #define ASSERT(c) if (!(c)) { printf("failed, line=%d\n", __LINE__); exit(1); }
     ASSERT(1152 == samples);
 
+    ret = mp3dec_detect_buf(0, size);
+    ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_detect_buf(buf, (size_t)-1);
+    ASSERT(MP3D_E_PARAM == ret);
+
     ret = mp3dec_load_buf(0, buf, size, &finfo, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_load_buf(&mp3d, 0, size, &finfo, 0, 0);
@@ -464,6 +469,11 @@
     memset(&finfo, 0xff, sizeof(finfo));
     ret = mp3dec_load_buf(&mp3d, buf, 0, &finfo, 0, 0);
     ASSERT(0 == ret && 0 == finfo.samples);
+
+    ret = mp3dec_detect_cb(&io, 0, size);
+    ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_detect_cb(&io, buf, (size_t)-1);
+    ASSERT(MP3D_E_PARAM == ret);
 
     ret = mp3dec_load_cb(0, &io, buf, size, &finfo, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -102,6 +102,12 @@
 # Delay and padding usage can be implemented if such software/files exists.
 [[ "$(./minimp3 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass
 [[ "$(./minimp3 -m 6 vectors/l3-nonstandard-vbrtag-noframes.bit)" != "rate=44100 samples=0 max_diff=0 PSNR=99.000000" ]] && echo fail && exit 1 || echo pass
+
+[[ "$(./minimp3 -m 9 vectors/l3-sin1k0db.pcm)" != "info: not an mp3/mpa file" ]] && echo fail && exit 1 || echo pass
+[[ "$(./minimp3 -m 9 vectors/l3-nonstandard-small.bit)" != "info: not an mp3/mpa file" ]] && echo fail && exit 1 || echo pass
+[[ "$(./minimp3 -m 11 -e 0 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
+[[ "$(./minimp3 -m 11 -e 1 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
+[[ "$(./minimp3 -m 11 -e 2 vectors/l3-sin1k0db.bit)" != "error: mp3dec_detect*()=-3 failed" ]] && echo fail && exit 1 || echo pass
 set -e
 
 ./minimp3 -m 6 -s 215 -b vectors/l3-sin1k0db.bit vectors/l3-sin1k0db.pcm