[xiph-commits] r3904 - liboggz/trunk/src/liboggz

conrad at svn.annodex.net conrad at svn.annodex.net
Tue Mar 31 04:44:14 PDT 2009


Author: conrad
Date: 2009-03-31 04:44:14 -0700 (Tue, 31 Mar 2009)
New Revision: 3904

Modified:
   liboggz/trunk/src/liboggz/oggz_auto.c
Log:
Fix size parsing error in auto_vorbis()
Patch by Ian Malone: If the size for the mode section doesn't match
the number counted back then allow going forward one block and trying
again. oggzinfo with and without this change produce the same results
on about 1500 vorbis files (though they're mostly encoded using the
same quality setting).
See http://lists.xiph.org/pipermail/vorbis-dev/2009-March/019823.html

Modified: liboggz/trunk/src/liboggz/oggz_auto.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_auto.c	2009-03-31 00:33:17 UTC (rev 3903)
+++ liboggz/trunk/src/liboggz/oggz_auto.c	2009-03-31 11:44:14 UTC (rev 3904)
@@ -686,6 +686,7 @@
 auto_calc_vorbis(ogg_int64_t now, oggz_stream_t *stream, ogg_packet *op) {
 
   auto_calc_vorbis_info_t *info;
+  int ii;
 
   if (stream->calculate_data == NULL) {
     /*
@@ -821,19 +822,32 @@
 
       }
 
-      if (offset > 4) {
-        size_check = (current_pos[0] >> (offset - 5)) & 0x3F;
-      } else {
-        /* mask part of byte from current_pos */
-        size_check = (current_pos[0] & ((1 << (offset + 1)) - 1));
-        /* shift to appropriate position */
-        size_check <<= (5 - offset);
-        /* or in part of byte from current_pos - 1 */
-        size_check |= (current_pos[-1] & ~((1 << (offset + 3)) - 1)) >>
-                (offset + 3);
+      /* Give ourselves a chance to recover if we went back too far by using
+       * the size check. */
+      for (ii=0; ii < 2; ii++) {
+       if (offset > 4) {
+         size_check = (current_pos[0] >> (offset - 5)) & 0x3F;
+       } else {
+         /* mask part of byte from current_pos */
+         size_check = (current_pos[0] & ((1 << (offset + 1)) - 1));
+         /* shift to appropriate position */
+         size_check <<= (5 - offset);
+         /* or in part of byte from current_pos - 1 */
+         size_check |= (current_pos[-1] & ~((1 << (offset + 3)) - 1)) >>
+           (offset + 3);
+       }
+
+       size_check += 1;
+       if (size_check == size) {
+         break;
+       }
+        offset = (offset + 1) % 8;
+        if (offset == 0)
+          current_pos += 1;
+       current_pos += 5;
+       size -= 1;
       }
 
-      size_check += 1;
 #ifdef DEBUG
       if (size_check != size)
       {



More information about the commits mailing list