[xiph-cvs] cvs commit: vorbis/lib block.c

Monty xiphmont at xiph.org
Tue Jul 2 22:26:18 PDT 2002



xiphmont    02/07/02 22:26:17

  Modified:    lib      block.c
  Log:
  fix two possible infinite loop bugs at end of stream, and bulletproof
  against innocent changes accidentally reawakening them

Revision  Changes    Path
1.66      +12 -7     vorbis/lib/block.c

Index: block.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis/lib/block.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- block.c	2002/06/28 22:19:35	1.65
+++ block.c	2002/07/03 05:26:17	1.66
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: PCM data vector blocking, windowing and dis/reassembly
- last mod: $Id: block.c,v 1.65 2002/06/28 22:19:35 xiphmont Exp $
+ last mod: $Id: block.c,v 1.66 2002/07/03 05:26:17 xiphmont Exp $
 
  Handle windowing, overlap-add, etc of the PCM vectors.  This is made
  more amusing by Vorbis' current two allowed block sizes.
@@ -427,14 +427,14 @@
       _preextrapolate_helper(v);
 
     /* We're encoding the end of the stream.  Just make sure we have
-       [at least] a full block of zeroes at the end. */
+       [at least] a few full blocks of zeroes at the end. */
     /* actually, we don't want zeroes; that could drop a large
        amplitude off a cliff, creating spread spectrum noise that will
        suck to encode.  Extrapolate for the sake of cleanliness. */
 
-    vorbis_analysis_buffer(v,ci->blocksizes[1]*2);
+    vorbis_analysis_buffer(v,ci->blocksizes[1]*3); 
     v->eofflag=v->pcm_current;
-    v->pcm_current+=ci->blocksizes[1]*2;
+    v->pcm_current+=ci->blocksizes[1]*3;
 
     for(i=0;i<vi->channels;i++){
       if(v->eofflag>order*2){
@@ -502,10 +502,14 @@
      marking impulses too. */
   {  
     long bp=_ve_envelope_search(v);
-    if(bp==-1)return(0); /* not enough data currently to search for a
-                            full long block */
+    if(bp==-1){
 
-    v->nW=bp;
+      if(v->eofflag==0)return(0); /* not enough data currently to search for a
+				     full long block */
+      v->nW=0;
+    }else{
+      v->nW=bp;
+    }
   }
 
   centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
@@ -614,6 +618,7 @@
       
       if(v->eofflag){
         v->eofflag-=movementW;
+	if(v->eofflag<=0)v->eofflag=-1;
         /* do not add padding to end of stream! */
         if(v->centerW>=v->eofflag){
           v->granulepos+=movementW-(v->centerW-v->eofflag);

<p><p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list