8b53c8c
Index: doc/Vorbis_I_spec.pdf
8b53c8c
===================================================================
8b53c8c
Cannot display: file marked as a binary type.
8b53c8c
svn:mime-type = application/pdf
8b53c8c
Index: lib/sharedbook.c
8b53c8c
===================================================================
8b53c8c
--- lib/sharedbook.c	(revision 14810)
8b53c8c
+++ lib/sharedbook.c	(revision 14811)
8b53c8c
@@ -124,7 +124,14 @@
8b53c8c
     }else
8b53c8c
       if(sparsecount==0)count++;
8b53c8c
   }
8b53c8c
-    
8b53c8c
+  
8b53c8c
+  /* sanity check the huffman tree; an underpopulated tree must be rejected. */
8b53c8c
+  for(i=1;i<33;i++)
8b53c8c
+    if(marker[i] & (0xffffffffUL>>(32-i))){
8b53c8c
+      _ogg_free(r);
8b53c8c
+      return(NULL);
8b53c8c
+    }
8b53c8c
+
8b53c8c
   /* bitreverse the words because our bitwise packer/unpacker is LSb
8b53c8c
      endian */
8b53c8c
   for(i=0,count=0;i
8b53c8c
Index: lib/block.c
8b53c8c
===================================================================
8b53c8c
--- lib/block.c	(revision 14810)
8b53c8c
+++ lib/block.c	(revision 14811)
8b53c8c
@@ -235,7 +235,8 @@
8b53c8c
     if(!ci->fullbooks){
8b53c8c
       ci->fullbooks=_ogg_calloc(ci->books,sizeof(*ci->fullbooks));
8b53c8c
       for(i=0;i<ci->books;i++){
8b53c8c
-	vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
8b53c8c
+	if(vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]))
8b53c8c
+	  return -1;
8b53c8c
 	/* decode codebooks are now standalone after init */
8b53c8c
 	vorbis_staticbook_destroy(ci->book_param[i]);
8b53c8c
 	ci->book_param[i]=NULL;
8b53c8c
@@ -694,9 +695,11 @@
8b53c8c
 }
8b53c8c
 
8b53c8c
 int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
8b53c8c
-  if(_vds_shared_init(v,vi,0)) return 1;
8b53c8c
+  if(_vds_shared_init(v,vi,0)){
8b53c8c
+    vorbis_dsp_clear(v);
8b53c8c
+    return 1;
8b53c8c
+  }
8b53c8c
   vorbis_synthesis_restart(v);
8b53c8c
-
8b53c8c
   return 0;
8b53c8c
 }
8b53c8c
 
8b53c8c
Index: examples/decoder_example.c
8b53c8c
===================================================================
8b53c8c
--- examples/decoder_example.c	(revision 14810)
8b53c8c
+++ examples/decoder_example.c	(revision 14811)
8b53c8c
@@ -198,108 +198,111 @@
8b53c8c
 
8b53c8c
     /* OK, got and parsed all three headers. Initialize the Vorbis
8b53c8c
        packet->PCM decoder. */
8b53c8c
-    vorbis_synthesis_init(&vd,&vi;; /* central decode state */
8b53c8c
-    vorbis_block_init(&vd,&vb;;     /* local state for most of the decode
8b53c8c
-				       so multiple block decodes can
8b53c8c
-				       proceed in parallel.  We could init
8b53c8c
-				       multiple vorbis_block structures
8b53c8c
-				       for vd here */
8b53c8c
-    
8b53c8c
-    /* The rest is just a straight decode loop until end of stream */
8b53c8c
-    while(!eos){
8b53c8c
+    if(vorbis_synthesis_init(&vd,&vi)==0){ /* central decode state */
8b53c8c
+      vorbis_block_init(&vd,&vb;;          /* local state for most of the decode
8b53c8c
+					      so multiple block decodes can
8b53c8c
+					      proceed in parallel.  We could init
8b53c8c
+					      multiple vorbis_block structures
8b53c8c
+					      for vd here */
8b53c8c
+      
8b53c8c
+      /* The rest is just a straight decode loop until end of stream */
8b53c8c
       while(!eos){
8b53c8c
-	int result=ogg_sync_pageout(&oy,&og);
8b53c8c
-	if(result==0)break; /* need more data */
8b53c8c
-	if(result<0){ /* missing or corrupt data at this page position */
8b53c8c
-	  fprintf(stderr,"Corrupt or missing data in bitstream; "
8b53c8c
-		  "continuing...\n");
8b53c8c
-	}else{
8b53c8c
-	  ogg_stream_pagein(&os,&og); /* can safely ignore errors at
8b53c8c
-					 this point */
8b53c8c
-	  while(1){
8b53c8c
-	    result=ogg_stream_packetout(&os,&op);
8b53c8c
-
8b53c8c
-	    if(result==0)break; /* need more data */
8b53c8c
-	    if(result<0){ /* missing or corrupt data at this page position */
8b53c8c
-	      /* no reason to complain; already complained above */
8b53c8c
-	    }else{
8b53c8c
-	      /* we have a packet.  Decode it */
8b53c8c
-	      float **pcm;
8b53c8c
-	      int samples;
8b53c8c
+	while(!eos){
8b53c8c
+	  int result=ogg_sync_pageout(&oy,&og);
8b53c8c
+	  if(result==0)break; /* need more data */
8b53c8c
+	  if(result<0){ /* missing or corrupt data at this page position */
8b53c8c
+	    fprintf(stderr,"Corrupt or missing data in bitstream; "
8b53c8c
+		    "continuing...\n");
8b53c8c
+	  }else{
8b53c8c
+	    ogg_stream_pagein(&os,&og); /* can safely ignore errors at
8b53c8c
+					   this point */
8b53c8c
+	    while(1){
8b53c8c
+	      result=ogg_stream_packetout(&os,&op);
8b53c8c
 	      
8b53c8c
-	      if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
8b53c8c
-		vorbis_synthesis_blockin(&vd,&vb;;
8b53c8c
-	      /* 
8b53c8c
-		 
8b53c8c
-	      **pcm is a multichannel float vector.  In stereo, for
8b53c8c
-	      example, pcm[0] is left, and pcm[1] is right.  samples is
8b53c8c
-	      the size of each channel.  Convert the float values
8b53c8c
-	      (-1.<=range<=1.) to whatever PCM format and write it out */
8b53c8c
-	      
8b53c8c
-	      while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
8b53c8c
-		int j;
8b53c8c
-		int clipflag=0;
8b53c8c
-		int bout=(samples
8b53c8c
+	      if(result==0)break; /* need more data */
8b53c8c
+	      if(result<0){ /* missing or corrupt data at this page position */
8b53c8c
+		/* no reason to complain; already complained above */
8b53c8c
+	      }else{
8b53c8c
+		/* we have a packet.  Decode it */
8b53c8c
+		float **pcm;
8b53c8c
+		int samples;
8b53c8c
 		
8b53c8c
-		/* convert floats to 16 bit signed ints (host order) and
8b53c8c
-		   interleave */
8b53c8c
-		for(i=0;i
8b53c8c
-		  ogg_int16_t *ptr=convbuffer+i;
8b53c8c
-		  float  *mono=pcm[i];
8b53c8c
-		  for(j=0;j
8b53c8c
+		if(vorbis_synthesis(&vb,&op)==0) /* test for success! */
8b53c8c
+		  vorbis_synthesis_blockin(&vd,&vb;;
8b53c8c
+		/* 
8b53c8c
+		   
8b53c8c
+		**pcm is a multichannel float vector.  In stereo, for
8b53c8c
+		example, pcm[0] is left, and pcm[1] is right.  samples is
8b53c8c
+		the size of each channel.  Convert the float values
8b53c8c
+		(-1.<=range<=1.) to whatever PCM format and write it out */
8b53c8c
+		
8b53c8c
+		while((samples=vorbis_synthesis_pcmout(&vd,&pcm))>0){
8b53c8c
+		  int j;
8b53c8c
+		  int clipflag=0;
8b53c8c
+		  int bout=(samples
8b53c8c
+		  
8b53c8c
+		  /* convert floats to 16 bit signed ints (host order) and
8b53c8c
+		     interleave */
8b53c8c
+		  for(i=0;i
8b53c8c
+		    ogg_int16_t *ptr=convbuffer+i;
8b53c8c
+		    float  *mono=pcm[i];
8b53c8c
+		    for(j=0;j
8b53c8c
 #if 1
8b53c8c
-		    int val=mono[j]*32767.f;
8b53c8c
+		      int val=mono[j]*32767.f;
8b53c8c
 #else /* optional dither */
8b53c8c
-		    int val=mono[j]*32767.f+drand48()-0.5f;
8b53c8c
+		      int val=mono[j]*32767.f+drand48()-0.5f;
8b53c8c
 #endif
8b53c8c
-		    /* might as well guard against clipping */
8b53c8c
-		    if(val>32767){
8b53c8c
-		      val=32767;
8b53c8c
-		      clipflag=1;
8b53c8c
+		      /* might as well guard against clipping */
8b53c8c
+		      if(val>32767){
8b53c8c
+			val=32767;
8b53c8c
+			clipflag=1;
8b53c8c
+		      }
8b53c8c
+		      if(val<-32768){
8b53c8c
+			val=-32768;
8b53c8c
+			clipflag=1;
8b53c8c
+		      }
8b53c8c
+		      *ptr=val;
8b53c8c
+		      ptr+=vi.channels;
8b53c8c
 		    }
8b53c8c
-		    if(val<-32768){
8b53c8c
-		      val=-32768;
8b53c8c
-		      clipflag=1;
8b53c8c
-		    }
8b53c8c
-		    *ptr=val;
8b53c8c
-		    ptr+=vi.channels;
8b53c8c
 		  }
8b53c8c
-		}
8b53c8c
-		
8b53c8c
-		if(clipflag)
8b53c8c
-		  fprintf(stderr,"Clipping in frame %ld\n",(long)(vd.sequence));
8b53c8c
-		
8b53c8c
-		
8b53c8c
-		fwrite(convbuffer,2*vi.channels,bout,stdout);
8b53c8c
-		
8b53c8c
-		vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
8b53c8c
-						   many samples we
8b53c8c
-						   actually consumed */
8b53c8c
-	      }	    
8b53c8c
+		  
8b53c8c
+		  if(clipflag)
8b53c8c
+		    fprintf(stderr,"Clipping in frame %ld\n",(long)(vd.sequence));
8b53c8c
+		  
8b53c8c
+		  
8b53c8c
+		  fwrite(convbuffer,2*vi.channels,bout,stdout);
8b53c8c
+		  
8b53c8c
+		  vorbis_synthesis_read(&vd,bout); /* tell libvorbis how
8b53c8c
+						      many samples we
8b53c8c
+						      actually consumed */
8b53c8c
+		}	    
8b53c8c
+	      }
8b53c8c
 	    }
8b53c8c
+	    if(ogg_page_eos(&og))eos=1;
8b53c8c
 	  }
8b53c8c
-	  if(ogg_page_eos(&og))eos=1;
8b53c8c
 	}
8b53c8c
+	if(!eos){
8b53c8c
+	  buffer=ogg_sync_buffer(&oy,4096);
8b53c8c
+	  bytes=fread(buffer,1,4096,stdin);
8b53c8c
+	  ogg_sync_wrote(&oy,bytes);
8b53c8c
+	  if(bytes==0)eos=1;
8b53c8c
+	}
8b53c8c
       }
8b53c8c
-      if(!eos){
8b53c8c
-	buffer=ogg_sync_buffer(&oy,4096);
8b53c8c
-	bytes=fread(buffer,1,4096,stdin);
8b53c8c
-	ogg_sync_wrote(&oy,bytes);
8b53c8c
-	if(bytes==0)eos=1;
8b53c8c
-      }
8b53c8c
+      
8b53c8c
+      /* ogg_page and ogg_packet structs always point to storage in
8b53c8c
+	 libvorbis.  They're never freed or manipulated directly */
8b53c8c
+      
8b53c8c
+      vorbis_block_clear(&vb;;
8b53c8c
+      vorbis_dsp_clear(&vd);
8b53c8c
+    }else{
8b53c8c
+      fprintf(stderr,"Error: Corrupt header during playback initialization.\n");
8b53c8c
     }
8b53c8c
-    
8b53c8c
+
8b53c8c
     /* clean up this logical bitstream; before exit we see if we're
8b53c8c
        followed by another [chained] */
8b53c8c
-
8b53c8c
+    
8b53c8c
     ogg_stream_clear(&os);
8b53c8c
-  
8b53c8c
-    /* ogg_page and ogg_packet structs always point to storage in
8b53c8c
-       libvorbis.  They're never freed or manipulated directly */
8b53c8c
-    
8b53c8c
-    vorbis_block_clear(&vb;;
8b53c8c
-    vorbis_dsp_clear(&vd);
8b53c8c
-	vorbis_comment_clear(&vc);
8b53c8c
+    vorbis_comment_clear(&vc);
8b53c8c
     vorbis_info_clear(&vi;;  /* must be called last */
8b53c8c
   }
8b53c8c