From ff67c8b500127406b0b89be773cd3e186cde0cf8 Mon Sep 17 00:00:00 2001 From: Tim Terriberry Date: Thu, 14 Oct 2010 01:09:06 +0000 Subject: Port r16328 and r16330 from libvorbis. ivorbisfile_example.c ignores an error code and plows ahead blindly if libvorbisidec reports the current bitstream section is bad (OV_EBADLINK). Retrying after the error crashes libvorbisidec due to the unitialized state. git-svn-id: https://svn.xiph.org/trunk/Tremor@17526 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- block.c | 25 ++++++++++++++++++------- ivorbisfile_example.c | 11 ++++++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index b41482c..4fff4ad 100644 --- a/block.c +++ b/block.c @@ -161,14 +161,16 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ b->window[1]=_vorbis_window(0,ci->blocksizes[1]/2); /* finish the codebooks */ - if(!ci->fullbooks){ + if(!ci->fullbooks) ci->fullbooks=(codebook *)_ogg_calloc(ci->books,sizeof(*ci->fullbooks)); - for(i=0;ibooks;i++){ - vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]); - /* decode codebooks are now standalone after init */ - vorbis_staticbook_destroy(ci->book_param[i]); - ci->book_param[i]=NULL; - } + for(i=0;ibooks;i++){ + if(ci->book_param[i]==NULL) + goto abort_books; + if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i])) + goto abort_books; + /* decode codebooks are now standalone after init */ + vorbis_staticbook_destroy(ci->book_param[i]); + ci->book_param[i]=NULL; } v->pcm_storage=ci->blocksizes[1]; @@ -191,6 +193,15 @@ static int _vds_init(vorbis_dsp_state *v,vorbis_info *vi){ ci->map_param[mapnum]); } return 0; +abort_books: + for(i=0;ibooks;i++){ + if(ci->book_param[i]!=NULL){ + vorbis_staticbook_destroy(ci->book_param[i]); + ci->book_param[i]=NULL; + } + } + vorbis_dsp_clear(v); + return -1; } int vorbis_synthesis_restart(vorbis_dsp_state *v){ diff --git a/ivorbisfile_example.c b/ivorbisfile_example.c index 1854fc4..7b0cf10 100644 --- a/ivorbisfile_example.c +++ b/ivorbisfile_example.c @@ -21,8 +21,8 @@ #include #include -#include -#include +#include "ivorbiscodec.h" +#include "ivorbisfile.h" #ifdef _WIN32 /* We need the following two to set stdin/stdout to binary */ #include @@ -69,7 +69,12 @@ int main(){ /* EOF */ eof=1; } else if (ret < 0) { - /* error in the stream. Not a problem, just reporting it in + if(ret==OV_EBADLINK){ + fprintf(stderr,"Corrupt bitstream section! Exiting.\n"); + exit(1); + } + + /* some other error in the stream. Not a problem, just reporting it in case we (the app) cares. In this case, we don't. */ } else { /* we don't bother dealing with sample rate changes, etc, but -- cgit v1.2.1