summaryrefslogtreecommitdiff
path: root/apps/codecs/libtremor/codebook.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libtremor/codebook.c')
-rw-r--r--apps/codecs/libtremor/codebook.c23
1 files changed, 12 insertions, 11 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 *************/
29int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){ 29static_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