aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Larimer <jlarimer@google.com>2015-08-20 01:16:29 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-08-20 01:16:29 +0000
commite519917f9a3fad675ec887715439a132f1982cdd (patch)
tree9f0208a6daf44705651b8f23e1418e12a8fe640e
parentf5fef23c56fc7f1f6dbfc61d385a8f8861d9777b (diff)
parent396a4d27ab46b2da0817c14d744ac0afa648b741 (diff)
downloadtremolo-e519917f9a3fad675ec887715439a132f1982cdd.tar.gz
am 396a4d27: am a06c9707: Merge "Add sanity checks to fix crash" into klp-dev
* commit '396a4d27ab46b2da0817c14d744ac0afa648b741': Add sanity checks to fix crash
-rw-r--r--Tremolo/codebook.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Tremolo/codebook.c b/Tremolo/codebook.c
index 0ff3529..66979dc 100644
--- a/Tremolo/codebook.c
+++ b/Tremolo/codebook.c
@@ -210,6 +210,20 @@ static int _make_words(char *l,long n,ogg_uint32_t *r,long quantvals,
}
}
+ // following sanity check copied from libvorbis
+ /* sanity check the huffman tree; an underpopulated tree must be
+ rejected. The only exception is the one-node pseudo-nil tree,
+ which appears to be underpopulated because the tree doesn't
+ really exist; there's only one possible 'codeword' or zero bits,
+ but the above tree-gen code doesn't mark that. */
+ if(b->used_entries != 1){
+ for(i=1;i<33;i++)
+ if(marker[i] & (0xffffffffUL>>(32-i))){
+ return 1;
+ }
+ }
+
+
return 0;
}