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 /apps/codecs/libtremor/codebook.c | |
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
Diffstat (limited to 'apps/codecs/libtremor/codebook.c')
-rw-r--r-- | apps/codecs/libtremor/codebook.c | 23 |
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 *************/ |
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 |