shithub: mp3dec

Download patch

ref: d607115bdbfbcb45824b9e415291efe7c8a42b0e
parent: ca285b2238643bedfc47107d7b5373a79d8b5026
author: lieff <lieff@users.noreply.github.com>
date: Mon Feb 24 10:37:49 EST 2020

test: zero buffer and no file cases

--- a/minimp3_ex.h
+++ b/minimp3_ex.h
@@ -220,7 +220,7 @@
 
 int mp3dec_load_cb(mp3dec_t *dec, mp3dec_io_t *io, uint8_t *buf, size_t buf_size, mp3dec_file_info_t *info, MP3D_PROGRESS_CB progress_cb, void *user_data)
 {
-    if (!dec || !buf || !info || (size_t)-1 == buf_size)
+    if (!dec || !buf || !info || (size_t)-1 == buf_size || (io && buf_size < MINIMP3_BUF_SIZE))
         return MP3D_E_PARAM;
     uint64_t detected_samples = 0;
     size_t orig_buf_size = buf_size;
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -372,6 +372,9 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_load_buf(&mp3d, buf, size, 0, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    memset(&finfo, 0xff, sizeof(finfo));
+    ret = mp3dec_load_buf(&mp3d, buf, 0, &finfo, 0, 0);
+    ASSERT(0 == ret && 0 == finfo.samples);
 
     ret = mp3dec_load_cb(0, &io, buf, size, &finfo, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
@@ -381,6 +384,8 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_load_cb(&mp3d, &io, buf, size, 0, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_load_cb(&mp3d, &io, buf, 0, &finfo, 0, 0);
+    ASSERT(MP3D_E_PARAM == ret);
 
     ret = mp3dec_iterate_buf(0, size, frames_iterate_cb, 0);
     ASSERT(MP3D_E_PARAM == ret);
@@ -388,6 +393,8 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_iterate_buf(buf, size, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_iterate_buf(buf, 0, frames_iterate_cb, 0);
+    ASSERT(0 == ret);
 
     ret = mp3dec_iterate_cb(0, buf, size, frames_iterate_cb, 0);
     ASSERT(MP3D_E_PARAM == ret);
@@ -397,6 +404,8 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_iterate_cb(&io, buf, size, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_iterate_cb(&io, buf, 0, frames_iterate_cb, 0);
+    ASSERT(MP3D_E_PARAM == ret);
 
     ret = mp3dec_ex_open_buf(0, buf, size, MP3D_SEEK_TO_SAMPLE);
     ASSERT(MP3D_E_PARAM == ret);
@@ -406,6 +415,10 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_ex_open_buf(&dec, buf, size, MP3D_SEEK_TO_SAMPLE + 1);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_ex_open_buf(&dec, buf, 0, MP3D_SEEK_TO_SAMPLE);
+    ASSERT(0 == ret);
+    ret = mp3dec_ex_read(&dec, (mp3d_sample_t*)buf, 10);
+    ASSERT(0 == ret);
 
     ret = mp3dec_ex_open_cb(0, &io, MP3D_SEEK_TO_SAMPLE);
     ASSERT(MP3D_E_PARAM == ret);
@@ -428,11 +441,15 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_load(&mp3d, input_file_name, 0, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_load(&mp3d, "not_foud", &finfo, 0, 0);
+    ASSERT(MP3D_E_IOERROR == ret);
 
     ret = mp3dec_iterate(0, frames_iterate_cb, 0);
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_iterate(input_file_name, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_iterate("not_foud", frames_iterate_cb, 0);
+    ASSERT(MP3D_E_IOERROR == ret);
 
     ret = mp3dec_ex_open(0, input_file_name, MP3D_SEEK_TO_SAMPLE);
     ASSERT(MP3D_E_PARAM == ret);
@@ -440,6 +457,8 @@
     ASSERT(MP3D_E_PARAM == ret);
     ret = mp3dec_ex_open(&dec, input_file_name, MP3D_SEEK_TO_SAMPLE + 1);
     ASSERT(MP3D_E_PARAM == ret);
+    ret = mp3dec_ex_open(&dec, "not_foud", MP3D_SEEK_TO_SAMPLE);
+    ASSERT(MP3D_E_IOERROR == ret);
 
     printf("passed\n");
     return 0;