[xiph-commits] r17760 - in trunk/theora: examples lib

giles at svn.xiph.org giles at svn.xiph.org
Thu Dec 16 10:57:36 PST 2010


Author: giles
Date: 2010-12-16 10:57:36 -0800 (Thu, 16 Dec 2010)
New Revision: 17760

Modified:
   trunk/theora/examples/encoder_example.c
   trunk/theora/lib/state.c
Log:
Reject th_info structs with a zero in the frame rate rational.

The specification says that the frame rate numerator and
denominator MUST both be greater than zero. This wasn't
checked as part of the structure validation code, and in
fact passing a zero value here caused a segfault.

The code now checks for this in oc_state_init() and returns
TH_EINVAL, which is causes th_encode_alloc() and oc_decode_alloc()
to return NULL.

A check for that NULL return is also added to encoder_example.c
to show that it may fail when an invalid th_info parameter is
passed.

Modified: trunk/theora/examples/encoder_example.c
===================================================================
--- trunk/theora/examples/encoder_example.c	2010-12-15 22:09:04 UTC (rev 17759)
+++ trunk/theora/examples/encoder_example.c	2010-12-16 18:57:36 UTC (rev 17760)
@@ -1577,6 +1577,11 @@
     else ti.pixel_fmt=TH_PF_444;
     td=th_encode_alloc(&ti);
     th_info_clear(&ti);
+    if(td==NULL){
+      fprintf(stderr,"Error: Could not create an encoder instance.\n");
+      fprintf(stderr,"Check that video parameters are valid.\n");
+      exit(1);
+    }
     /* setting just the granule shift only allows power-of-two keyframe
        spacing.  Set the actual requested spacing. */
     ret=th_encode_ctl(td,TH_ENCCTL_SET_KEYFRAME_FREQUENCY_FORCE,

Modified: trunk/theora/lib/state.c
===================================================================
--- trunk/theora/lib/state.c	2010-12-15 22:09:04 UTC (rev 17759)
+++ trunk/theora/lib/state.c	2010-12-16 18:57:36 UTC (rev 17760)
@@ -702,7 +702,8 @@
      how it is specified in the bitstream, because the Y axis is flipped in
      the bitstream.
     The displayable frame must fit inside the encoded frame.
-    The color space must be one known by the encoder.*/
+    The color space must be one known by the encoder.
+    The framerate ratio must not contain a zero value.*/
   if((_info->frame_width&0xF)||(_info->frame_height&0xF)||
    _info->frame_width<=0||_info->frame_width>=0x100000||
    _info->frame_height<=0||_info->frame_height>=0x100000||
@@ -715,7 +716,8 @@
       but there are a number of compilers which will mis-optimize this.
      It's better to live with the spurious warnings.*/
    _info->colorspace<0||_info->colorspace>=TH_CS_NSPACES||
-   _info->pixel_fmt<0||_info->pixel_fmt>=TH_PF_NFORMATS){
+   _info->pixel_fmt<0||_info->pixel_fmt>=TH_PF_NFORMATS||
+   _info->fps_numerator<1||_info->fps_denominator<1){
     return TH_EINVAL;
   }
   memset(_state,0,sizeof(*_state));



More information about the commits mailing list