summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNedeljko Babic <nbabic@mips.com>2012-03-29 13:56:36 +0200
committerNedeljko Babic <nbabic@mips.com>2012-04-03 15:38:03 +0200
commit4ade16cbfab82e99e1950b599c194d8c5ccac32b (patch)
tree4cb3a76a5319eb00936b627f7efaaef0397b1e72
parent7bcd65d56a93c385a64020a256b37179eab7c6fe (diff)
downloadtremor-4ade16cbfab82e99e1950b599c194d8c5ccac32b.tar.gz
floor0 code could potentially use a book where the number of vals it
needed to decode was not an integer number of dims wide. This caused it to overflow the output vector as the termination condition was in the outer loop of vorbis_book_decodev_set. None of the various vorbis_book_decodeXXXX calls internally guard against this case either, but in every other use the calling code does properly guard (and avoids putting more checks in the tight inner decode loop). For floor0, move the checks into the inner loop as there's little penalty for doing so. Add commentary indicating where guarding is done. [Import part of changes from Tremor (80661a1 2010-10-18)]
-rw-r--r--codebook.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/codebook.c b/codebook.c
index 567a4f5..7234fd7 100644
--- a/codebook.c
+++ b/codebook.c
@@ -825,6 +825,9 @@ long vorbis_book_decodev_add(codebook *book,ogg_int32_t *a,
return 0;
}
+/* unlike the others, we guard against n not being an integer number
+ of <dim> internally rather than in the upper layer (called only by
+ floor0) */
long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
oggpack_buffer *b,int n,int point){
if(book->used_entries>0){
@@ -834,14 +837,13 @@ long vorbis_book_decodev_set(codebook *book,ogg_int32_t *a,
if (!v) return -1;
for(i=0;i<n;){
if(decode_map(book,b,v,point))return -1;
- for (j=0;j<book->dim;j++)
+ for (j=0;i<n && j<book->dim;j++)
a[i++]=v[j];
}
}else{
int i,j;
for(i=0;i<n;){
- for (j=0;j<book->dim;j++)
a[i++]=0;
}
}