Division by zero in libtheora-1.0

Marco Giovannini <[email protected]>
Newsgroups gmane.comp.multimedia.ogg.theora.devel
Organization Traderlink S.r.l
Message-ID <[email protected]>
Hello everybody,

while developing an application for the company I work for, I noticed 
that very often libtheora reports division by zero errors. I fixed those 
errors by adding a few additional checks, but I'm not 100% sure that 
these checks are correct.

Could you please check out the attached patch file and tell me what you 
think?

Best regards,
Marco Giovannini
-- 
/*
  *========================================================
  * Marco Giovannini
  * Software Engineer
  * ------------------------------------------------------
  * TRADERLINK S.r.l.
  * Via IV Giugno, 84
  * Republic of San Marino
  * Tel. (+378) 0549 900757
  * ------------------------------------------------------
  * http://www.traderlink.it
  *========================================================
  */

_______________________________________________
theora-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/theora-dev
theora_mg.patch (text/plain, 881 B)
Index: lib/enc/encoder_toplevel.c
===================================================================
--- lib/enc/encoder_toplevel.c	(revision 15558)
+++ lib/enc/encoder_toplevel.c	(working copy)
@@ -705,7 +705,7 @@
   /* Calculate the Q Modifier step size required to cause a step down
      from full target bandwidth to 40% of target between max Q and
      best Q */
-  QModStep = 0.5 / (double)((Q_TABLE_SIZE - 1) -
+  QModStep = 0.5 / (double)((Q_TABLE_SIZE) -
                             cpi->Configuration.ActiveMaxQ);

   /* Set up the cpi->QTargetModifier[] table. */
@@ -755,6 +755,9 @@
                                 Configuration.TargetBandwidth)) * 0.0175) ));
   }

+  if (cpi->ThisFrameTargetBytes <= 0)
+    cpi->ThisFrameTargetBytes = 1;
+
   if ( !DropFrame ) {
     /*  pick all the macroblock modes and motion vectors */
     ogg_uint32_t InterError;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.