shithub: mp3dec

Download patch

ref: d17a0a68c828796c9f3980ec5a1feb921d2897c4
parent: 0a83e96c77757d10a83cfc73a32f8a506b34d67d
author: lieff <[email protected]>
date: Wed Feb 19 07:49:02 EST 2020

mp3dec_ex: fail mp3dec_ex_read on last_error state and reset last_error on seek

--- a/minimp3_ex.h
+++ b/minimp3_ex.h
@@ -749,6 +749,7 @@
     dec->buffer_consumed = 0;
     dec->input_consumed  = 0;
     dec->input_filled    = 0;
+    dec->last_error      = 0;
     mp3dec_init(&dec->mp3d);
     return 0;
 }
@@ -764,6 +765,8 @@
     memset(&frame_info, 0, sizeof(frame_info));
     if (dec->detected_samples && dec->cur_sample >= dec->detected_samples)
         return 0; /* at end of stream */
+    if (dec->last_error)
+        return 0; /* error eof state, seek can reset it */
     if (dec->buffer_consumed < dec->buffer_samples)
     {
         size_t to_copy = MINIMP3_MIN((size_t)(dec->buffer_samples - dec->buffer_consumed), samples);
@@ -791,7 +794,8 @@
                 dec->input_filled -= dec->input_consumed;
                 dec->input_consumed = 0;
                 size_t readed = dec->io->read((uint8_t*)dec->file.buffer + dec->input_filled, dec->file.size - dec->input_filled, dec->io->read_data);
-                dec->last_error = (readed > (dec->file.size - dec->input_filled)) ? MP3D_E_IOERROR : 0;
+                if (readed > (dec->file.size - dec->input_filled))
+                    dec->last_error = MP3D_E_IOERROR;
                 if (readed != (dec->file.size - dec->input_filled))
                     eof = 1;
                 dec->input_filled += readed;