[xiph-commits] r3446 - in liboggz/trunk/src: liboggz tests

conrad at svn.annodex.net conrad at svn.annodex.net
Mon Feb 11 22:17:46 PST 2008


Author: conrad
Date: 2008-02-11 22:17:45 -0800 (Mon, 11 Feb 2008)
New Revision: 3446

Added:
   liboggz/trunk/src/tests/write-bad-serialno.c
Modified:
   liboggz/trunk/src/liboggz/oggz_write.c
   liboggz/trunk/src/tests/Makefile.am
Log:
re-enable check that serialno is within 32bit range in oggz_write_feed, and
add a test for rejecting invalid serialnos. Tested on ILP32 and LP64.


Modified: liboggz/trunk/src/liboggz/oggz_write.c
===================================================================
--- liboggz/trunk/src/liboggz/oggz_write.c	2008-02-12 05:24:36 UTC (rev 3445)
+++ liboggz/trunk/src/liboggz/oggz_write.c	2008-02-12 06:17:45 UTC (rev 3446)
@@ -225,11 +225,11 @@
 
   /* Check that the serialno is in the valid range for an Ogg page header,
    * ie. that it fits within 32 bits and does not equal the special value -1 */
-  if ((serialno & 0xffffffff) != (unsigned int) serialno || serialno == -1) {
+  if ((long)((ogg_int32_t)serialno) != serialno || serialno == -1) {
 #ifdef DEBUG
     printf ("oggz_write_feed: serialno %010ld\n", serialno);
 #endif
-    /*return OGGZ_ERR_BAD_SERIALNO;*/
+    return OGGZ_ERR_BAD_SERIALNO;
   }
 
 #ifdef DEBUG

Modified: liboggz/trunk/src/tests/Makefile.am
===================================================================
--- liboggz/trunk/src/tests/Makefile.am	2008-02-12 05:24:36 UTC (rev 3445)
+++ liboggz/trunk/src/tests/Makefile.am	2008-02-12 06:17:45 UTC (rev 3446)
@@ -16,7 +16,8 @@
 if OGGZ_CONFIG_WRITE
 write_tests = write-bad-guard write-unmarked-guard write-recursive \
 	write-bad-bytes write-bad-bos write-dup-bos write-bad-eos \
-	write-bad-granulepos write-bad-packetno write-prefix write-suffix
+	write-bad-granulepos write-bad-packetno write-bad-serialno \
+	write-prefix write-suffix
 endif
 
 if OGGZ_CONFIG_READ
@@ -70,6 +71,9 @@
 write_bad_packetno_SOURCES = write-bad-packetno.c
 write_bad_packetno_LDADD = $(OGGZ_LIBS)
 
+write_bad_serialno_SOURCES = write-bad-serialno.c
+write_bad_serialno_LDADD = $(OGGZ_LIBS)
+
 write_prefix_SOURCES = write-prefix.c
 write_prefix_LDADD = $(OGGZ_LIBS)
 write_suffix_SOURCES = write-suffix.c

Added: liboggz/trunk/src/tests/write-bad-serialno.c
===================================================================
--- liboggz/trunk/src/tests/write-bad-serialno.c	                        (rev 0)
+++ liboggz/trunk/src/tests/write-bad-serialno.c	2008-02-12 06:17:45 UTC (rev 3446)
@@ -0,0 +1,86 @@
+/*
+   Copyright (C) 2008 Annodex Association, Inc.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions
+   are met:
+
+   - Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+
+   - Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+
+   - Neither the name of the Annodex Association nor the names of its
+   contributors may be used to endorse or promote products derived from
+   this software without specific prior written permission.
+
+   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+   PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ASSOCIATION OR
+   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <oggz/oggz.h>
+
+#include "oggz_tests.h"
+
+static const long good_serialno = 0x77L;
+static const long bad_serialno = (long)0x777777777777LL;
+
+int
+main (int argc, char * argv[])
+{
+  OGGZ * oggz;
+  unsigned char buf[1];
+  ogg_packet op;
+  long n;
+
+  oggz = oggz_new (OGGZ_WRITE);
+  if (oggz == NULL)
+    FAIL("newly created OGGZ == NULL");
+
+  /* Create a packet */
+  buf[0] = 'x';
+  op.packet = buf;
+  op.bytes = 1;
+  op.granulepos = 0;
+  op.packetno = 0;
+  op.b_o_s = 1;
+  op.e_o_s = 0;
+    
+  /* Feed it to the Oggz packet queue, first normally, then twice with a
+   * bad serialno */
+
+  INFO ("Feeding packet with ok serialno");
+  if (oggz_write_feed (oggz, &op, good_serialno, 0, NULL) != 0)
+    FAIL ("Error feeding with valid serialno");
+
+  INFO ("Feeding packet with -1 serialno");
+  if (oggz_write_feed (oggz, &op, -1L, 0, NULL) != OGGZ_ERR_BAD_SERIALNO)
+    FAIL ("Illegal serialno (-1) not detected");
+    
+  /* The following test is only active where long and int have different
+   * sizes, eg. on LP64 platforms */
+  if (sizeof(long) > sizeof(int)) {
+    INFO ("Detected sizeof(long) > sizeof(int)")
+
+    INFO ("Feeding packet with out-of-range serialno");
+    if (oggz_write_feed (oggz, &op, bad_serialno, 0, NULL) !=
+        OGGZ_ERR_BAD_SERIALNO)
+      FAIL ("Out-of-range serialno not detected");
+  }
+
+  if (oggz_close (oggz) != 0)
+    FAIL("Could not close OGGZ");
+
+  exit (0);
+}



More information about the commits mailing list