Don't crash on corrupt files

b/13652927

Change-Id: I33cd8e0ba9deda1c8aefe39120df90f42aead529
diff --git a/Tremolo/codebook.c b/Tremolo/codebook.c
index 781ea10..27903b5 100644
--- a/Tremolo/codebook.c
+++ b/Tremolo/codebook.c
@@ -239,13 +239,14 @@
   if (s->used_entries > INT_MAX/2 ||
       s->used_entries*2 > INT_MAX/((long) sizeof(*work)) - 1) return 1;
   /* Overallocate as above */
-  work=alloca((s->entries*2+1)*sizeof(*work));
-  if(_make_words(lengthlist,s->entries,work,quantvals,s,opb,maptype))return 1;
-  if (s->used_entries > INT_MAX/(s->dec_leafw+1)) return 1;
-  if (s->dec_nodeb && s->used_entries * (s->dec_leafw+1) > INT_MAX/s->dec_nodeb) return 1;
+  work=calloc((s->entries*2+1),sizeof(*work));
+  if (!work) return 1;
+  if(_make_words(lengthlist,s->entries,work,quantvals,s,opb,maptype)) goto error_out;
+  if (s->used_entries > INT_MAX/(s->dec_leafw+1)) goto error_out;
+  if (s->dec_nodeb && s->used_entries * (s->dec_leafw+1) > INT_MAX/s->dec_nodeb) goto error_out;
   s->dec_table=_ogg_malloc((s->used_entries*(s->dec_leafw+1)-2)*
 			   s->dec_nodeb);
-  if (!s->dec_table) return 1;
+  if (!s->dec_table) goto error_out;
 
   if(s->dec_leafw==1){
     switch(s->dec_nodeb){
@@ -329,7 +330,11 @@
     }
   }
 
+  free(work);
   return 0;
+error_out:
+  free(work);
+  return 1;
 }
 
 /* most of the time, entries%dimensions == 0, but we need to be