Commit 1535dbf7 authored by conrad's avatar conrad

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.


git-svn-id: http://svn.annodex.net/liboggz/trunk@3446 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 95641ae4
......@@ -225,11 +225,11 @@ oggz_write_feed (OGGZ * oggz, ogg_packet * op, long serialno, int flush,
/* 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
......
......@@ -16,7 +16,8 @@ comment_tests = comment-test
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_granulepos_LDADD = $(OGGZ_LIBS)
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
......
/*
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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment