shithub: mp3dec

Download patch

ref: e0c78630f834bc19b7ecc16638ebfcbfdad70299
parent: 30b3a2c82db22e44acccb8c92fa3ce77f0be0ef5
author: lieff <[email protected]>
date: Sat Aug 15 11:10:45 EDT 2020

Report MP3D_E_PARAM error in dec->last_error for mp3dec_ex_read.

--- a/minimp3_ex.h
+++ b/minimp3_ex.h
@@ -18,6 +18,7 @@
 /*#define MINIMP3_SEEK_IDX_LINEAR_SEARCH*/ /* define to use linear index search instead of binary search on seek */
 #define MINIMP3_IO_SIZE (128*1024) /* io buffer size for streaming functions, must be greater than MINIMP3_BUF_SIZE */
 #define MINIMP3_BUF_SIZE (16*1024) /* buffer which can hold minimum 10 consecutive mp3 frames (~16KB) worst case */
+/*#define MINIMP3_SCAN_LIMIT (256*1024)*/ /* how many bytes will be scanned to search first valid mp3 frame, to prevent stall on large non-mp3 files */
 #define MINIMP3_ENABLE_RING 0      /* WIP enable hardware magic ring buffer if available, to make less input buffer memmove(s) in callback IO mode */
 
 /* return error codes */
@@ -845,7 +846,11 @@
 size_t mp3dec_ex_read(mp3dec_ex_t *dec, mp3d_sample_t *buf, size_t samples)
 {
     if (!dec || !buf)
-        return MP3D_E_PARAM;
+    {
+        if (dec)
+            dec->last_error = MP3D_E_PARAM;
+        return 0;
+    }
     uint64_t end_offset = dec->end_offset ? dec->end_offset : dec->file.size;
     size_t samples_requested = samples;
     int eof = 0;
--- a/minimp3_test.c
+++ b/minimp3_test.c
@@ -531,9 +531,9 @@
     ASSERT(MP3D_E_PARAM == ret);
 
     ret = mp3dec_ex_read(0, (mp3d_sample_t*)buf, 10);
-    ASSERT(MP3D_E_PARAM == ret);
+    ASSERT(0 == ret); /* invalid param case, no decoder structure to report an error */
     ret = mp3dec_ex_read(&dec, 0, 10);
-    ASSERT(MP3D_E_PARAM == ret);
+    ASSERT(0 == ret && MP3D_E_PARAM == dec.last_error); /* invalid param case */
 
     ret = mp3dec_load(0, input_file_name, &finfo, 0, 0);
     ASSERT(MP3D_E_PARAM == ret);