diff options
author | Nils Wallménius <nils@rockbox.org> | 2010-12-08 16:07:46 +0000 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2010-12-08 16:07:46 +0000 |
commit | c0e3e1628575647ec9083fd23c26de85ea8f86c0 (patch) | |
tree | 8c19a660d381df5c1c8d0468b4fac3f6cb1ff995 | |
parent | a5897697f9d38b3a7131a504c7251ac5fe2dcb15 (diff) | |
download | rockbox-c0e3e1628575647ec9083fd23c26de85ea8f86c0.tar.gz rockbox-c0e3e1628575647ec9083fd23c26de85ea8f86c0.zip |
libtremor: merge upstream revision 17528-17530, more error checking and bug fixes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28768 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/libtremor/codebook.c | 23 | ||||
-rw-r--r-- | apps/codecs/libtremor/codebook.h | 3 | ||||
-rw-r--r-- | apps/codecs/libtremor/info.c | 4 | ||||
-rw-r--r-- | apps/codecs/libtremor/sharedbook.c | 7 | ||||
-rw-r--r-- | apps/codecs/libtremor/synthesis.c | 18 |
5 files changed, 29 insertions, 26 deletions
diff --git a/apps/codecs/libtremor/codebook.c b/apps/codecs/libtremor/codebook.c index 2b92e216cc..fd473280b2 100644 --- a/apps/codecs/libtremor/codebook.c +++ b/apps/codecs/libtremor/codebook.c | |||
@@ -26,9 +26,9 @@ | |||
26 | 26 | ||
27 | /* unpacks a codebook from the packet buffer into the codebook struct, | 27 | /* unpacks a codebook from the packet buffer into the codebook struct, |
28 | readies the codebook auxiliary structures for decode *************/ | 28 | readies the codebook auxiliary structures for decode *************/ |
29 | int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ | 29 | static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ |
30 | long i,j; | 30 | long i,j; |
31 | memset(s,0,sizeof(*s)); | 31 | static_codebook *s=_ogg_calloc(1,sizeof(*s)); |
32 | 32 | ||
33 | /* make sure alignment is correct */ | 33 | /* make sure alignment is correct */ |
34 | if(oggpack_read(opb,24)!=0x564342)goto _eofout; | 34 | if(oggpack_read(opb,24)!=0x564342)goto _eofout; |
@@ -75,17 +75,18 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ | |||
75 | s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); | 75 | s->lengthlist=(long *)_ogg_malloc(sizeof(*s->lengthlist)*s->entries); |
76 | 76 | ||
77 | for(i=0;i<s->entries;){ | 77 | for(i=0;i<s->entries;){ |
78 | long num=oggpack_read(opb,_ilog(s->entries-i)); | 78 | long num=oggpack_read(opb,_ilog(s->entries-i)); |
79 | if(num==-1)goto _eofout; | 79 | if(num==-1)goto _eofout; |
80 | for(j=0;j<num && i<s->entries;j++,i++) | 80 | if(length>32)goto _errout; |
81 | s->lengthlist[i]=length; | 81 | for(j=0;j<num && i<s->entries;j++,i++) |
82 | length++; | 82 | s->lengthlist[i]=length; |
83 | length++; | ||
83 | } | 84 | } |
84 | } | 85 | } |
85 | break; | 86 | break; |
86 | default: | 87 | default: |
87 | /* EOF */ | 88 | /* EOF */ |
88 | return(-1); | 89 | goto _eofout; |
89 | } | 90 | } |
90 | 91 | ||
91 | /* Do we have a mapping to unpack? */ | 92 | /* Do we have a mapping to unpack? */ |
@@ -127,12 +128,12 @@ int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ | |||
127 | } | 128 | } |
128 | 129 | ||
129 | /* all set */ | 130 | /* all set */ |
130 | return(0); | 131 | return(s); |
131 | 132 | ||
132 | _errout: | 133 | _errout: |
133 | _eofout: | 134 | _eofout: |
134 | vorbis_staticbook_clear(s); | 135 | vorbis_staticbook_destroy(s); |
135 | return(-1); | 136 | return(NULL); |
136 | } | 137 | } |
137 | 138 | ||
138 | /* the 'eliminate the decode tree' optimization actually requires the | 139 | /* the 'eliminate the decode tree' optimization actually requires the |
diff --git a/apps/codecs/libtremor/codebook.h b/apps/codecs/libtremor/codebook.h index b13334d8d7..29ac9fd923 100644 --- a/apps/codecs/libtremor/codebook.h +++ b/apps/codecs/libtremor/codebook.h | |||
@@ -76,14 +76,13 @@ typedef struct codebook{ | |||
76 | 76 | ||
77 | } codebook; | 77 | } codebook; |
78 | 78 | ||
79 | extern void vorbis_staticbook_clear(static_codebook *b); | ||
80 | extern void vorbis_staticbook_destroy(static_codebook *b); | 79 | extern void vorbis_staticbook_destroy(static_codebook *b); |
81 | extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); | 80 | extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source); |
82 | 81 | ||
83 | extern void vorbis_book_clear(codebook *b); | 82 | extern void vorbis_book_clear(codebook *b); |
84 | extern long _book_maptype1_quantvals(const static_codebook *b); | 83 | extern long _book_maptype1_quantvals(const static_codebook *b); |
85 | 84 | ||
86 | extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c); | 85 | extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b); |
87 | 86 | ||
88 | extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); | 87 | extern long vorbis_book_decode(codebook *book, oggpack_buffer *b); |
89 | extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a, | 88 | extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a, |
diff --git a/apps/codecs/libtremor/info.c b/apps/codecs/libtremor/info.c index b819570682..b21d08de49 100644 --- a/apps/codecs/libtremor/info.c +++ b/apps/codecs/libtremor/info.c | |||
@@ -168,8 +168,8 @@ static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){ | |||
168 | ci->books=oggpack_read(opb,8)+1; | 168 | ci->books=oggpack_read(opb,8)+1; |
169 | if(ci->books<=0)goto err_out; | 169 | if(ci->books<=0)goto err_out; |
170 | for(i=0;i<ci->books;i++){ | 170 | for(i=0;i<ci->books;i++){ |
171 | ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i])); | 171 | ci->book_param[i]=vorbis_staticbook_unpack(opb); |
172 | if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out; | 172 | if(!ci->book_param[i])goto err_out; |
173 | } | 173 | } |
174 | 174 | ||
175 | /* time backend settings */ | 175 | /* time backend settings */ |
diff --git a/apps/codecs/libtremor/sharedbook.c b/apps/codecs/libtremor/sharedbook.c index 884920ecda..e9cdd13329 100644 --- a/apps/codecs/libtremor/sharedbook.c +++ b/apps/codecs/libtremor/sharedbook.c | |||
@@ -295,15 +295,10 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n, | |||
295 | return(NULL); | 295 | return(NULL); |
296 | } | 296 | } |
297 | 297 | ||
298 | void vorbis_staticbook_clear(static_codebook *b){ | 298 | void vorbis_staticbook_destroy(static_codebook *b){ |
299 | if(b->quantlist)_ogg_free(b->quantlist); | 299 | if(b->quantlist)_ogg_free(b->quantlist); |
300 | if(b->lengthlist)_ogg_free(b->lengthlist); | 300 | if(b->lengthlist)_ogg_free(b->lengthlist); |
301 | memset(b,0,sizeof(*b)); | 301 | memset(b,0,sizeof(*b)); |
302 | |||
303 | } | ||
304 | |||
305 | void vorbis_staticbook_destroy(static_codebook *b){ | ||
306 | vorbis_staticbook_clear(b); | ||
307 | _ogg_free(b); | 302 | _ogg_free(b); |
308 | } | 303 | } |
309 | 304 | ||
diff --git a/apps/codecs/libtremor/synthesis.c b/apps/codecs/libtremor/synthesis.c index c47f381592..657aa74e11 100644 --- a/apps/codecs/libtremor/synthesis.c +++ b/apps/codecs/libtremor/synthesis.c | |||
@@ -28,13 +28,17 @@ | |||
28 | static ogg_int32_t *ipcm_vect[CHANNELS] IBSS_ATTR; | 28 | static ogg_int32_t *ipcm_vect[CHANNELS] IBSS_ATTR; |
29 | 29 | ||
30 | static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ | 30 | static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ |
31 | vorbis_dsp_state *vd=vb->vd; | 31 | vorbis_dsp_state *vd= vb ? vb->vd : 0; |
32 | private_state *b=(private_state *)vd->backend_state; | 32 | private_state *b= vd ? (private_state *)vd->backend_state: 0; |
33 | vorbis_info *vi=vd->vi; | 33 | vorbis_info *vi= vd ? vd->vi : 0; |
34 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; | 34 | codec_setup_info *ci= vi ? (codec_setup_info *)vi->codec_setup : 0; |
35 | oggpack_buffer *opb=&vb->opb; | 35 | oggpack_buffer *opb=vb ? &vb->opb : 0; |
36 | int type,mode,i; | 36 | int type,mode,i; |
37 | 37 | ||
38 | if (!vd || !b || !vi || !ci || !opb) { | ||
39 | return OV_EBADPACKET; | ||
40 | } | ||
41 | |||
38 | /* first things first. Make sure decode is ready */ | 42 | /* first things first. Make sure decode is ready */ |
39 | _vorbis_block_ripcord(vb); | 43 | _vorbis_block_ripcord(vb); |
40 | oggpack_readinit(opb,op->packet,op->bytes); | 44 | oggpack_readinit(opb,op->packet,op->bytes); |
@@ -50,6 +54,10 @@ static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep | |||
50 | if(mode==-1)return(OV_EBADPACKET); | 54 | if(mode==-1)return(OV_EBADPACKET); |
51 | 55 | ||
52 | vb->mode=mode; | 56 | vb->mode=mode; |
57 | if(!ci->mode_param[mode]){ | ||
58 | return(OV_EBADPACKET); | ||
59 | } | ||
60 | |||
53 | vb->W=ci->mode_param[mode]->blockflag; | 61 | vb->W=ci->mode_param[mode]->blockflag; |
54 | if(vb->W){ | 62 | if(vb->W){ |
55 | vb->lW=oggpack_read(opb,1); | 63 | vb->lW=oggpack_read(opb,1); |