From 2ec38f98cc87d6018d557525dcc8fb57002d33c4 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Fri, 16 Sep 2016 11:42:00 +1000 Subject: [PATCH] Update libogg to 1.3.2 --- Engine/lib/libogg/CHANGES | 25 +- .../lib/libogg/include/ogg/config_types.h.in | 25 ++ Engine/lib/libogg/include/ogg/os_types.h | 4 +- Engine/lib/libogg/src/bitwise.c | 265 ++++++++++++++++-- Engine/lib/libogg/src/framing.c | 46 ++- Tools/CMake/libraries/libogg.cmake | 15 + 6 files changed, 340 insertions(+), 40 deletions(-) create mode 100644 Engine/lib/libogg/include/ogg/config_types.h.in diff --git a/Engine/lib/libogg/CHANGES b/Engine/lib/libogg/CHANGES index 411e7f58d..3f2e0fb26 100644 --- a/Engine/lib/libogg/CHANGES +++ b/Engine/lib/libogg/CHANGES @@ -1,3 +1,14 @@ +Version 1.3.2 (2014 May 27) + + * Fix an bug in oggpack_writecopy(). + +Version 1.3.1 (2013 May 12) + +* Guard against very large packets. +* Respect the configure --docdir override. +* Documentation fixes. +* More Windows build fixes. + Version 1.3.0 (2011 August 4) * Add ogg_stream_flush_fill() call @@ -17,25 +28,25 @@ Version 1.2.1 (2010 November 01) * Add ogg_stream_pageout_fill() to API to allow applications greater explicit flexibility in page sizing. * Documentation updates including multiplexing description, - terminology and API (incl. ogg_packet_clear(), + terminology and API (incl. ogg_packet_clear(), ogg_stream_pageout_fill()) -* Correct possible buffer overwrite in stream encoding on 32 bit +* Correct possible buffer overwrite in stream encoding on 32 bit when a single packet exceed 250MB. -* Correct read-buffer overrun [without side effects] under +* Correct read-buffer overrun [without side effects] under similar circumstances. * Update unit testing to work properly with new page spill heuristic. Version 1.2.0 (2010 March 25) -* Alter default flushing behavior to span less often and use larger page +* Alter default flushing behavior to span less often and use larger page sizes when packet sizes are large. * Build fixes for additional compilers * Documentation updates Version 1.1.4 (2009 June 24) -* New async error reporting mechanism. Calls made after a fatal error are +* New async error reporting mechanism. Calls made after a fatal error are now safely handled in the event an error code is ignored * Added allocation checks useful to some embedded applications * fix possible read past end of buffer when reading 0 bits @@ -47,7 +58,7 @@ Version 1.1.3 (2005 November 27) * Correct a bug in the granulepos field of pages where no packet ends * New VS2003 and XCode builds, minor fixes to other builds * documentation fixes and cleanup - + Version 1.1.2 (2004 September 23) * fix a bug with multipage packet assembly after seek @@ -68,7 +79,7 @@ Version 1.1 (2003 November 17) * improved API documenation * RFC 3533 documentation of the format by Silvia Pfeiffer at CSIRO * RFC 3534 documentation of the application/ogg mime-type by Linus Walleij - + Version 1.0 (2002 July 19) * First stable release diff --git a/Engine/lib/libogg/include/ogg/config_types.h.in b/Engine/lib/libogg/include/ogg/config_types.h.in new file mode 100644 index 000000000..750e29ddc --- /dev/null +++ b/Engine/lib/libogg/include/ogg/config_types.h.in @@ -0,0 +1,25 @@ +#ifndef __CONFIG_TYPES_H__ +#define __CONFIG_TYPES_H__ + +/* these are filled in by configure */ +#define INCLUDE_INTTYPES_H @INCLUDE_INTTYPES_H@ +#define INCLUDE_STDINT_H @INCLUDE_STDINT_H@ +#define INCLUDE_SYS_TYPES_H @INCLUDE_SYS_TYPES_H@ + +#if INCLUDE_INTTYPES_H +# include +#endif +#if INCLUDE_STDINT_H +# include +#endif +#if INCLUDE_SYS_TYPES_H +# include +#endif + +typedef @SIZE16@ ogg_int16_t; +typedef @USIZE16@ ogg_uint16_t; +typedef @SIZE32@ ogg_int32_t; +typedef @USIZE32@ ogg_uint32_t; +typedef @SIZE64@ ogg_int64_t; + +#endif diff --git a/Engine/lib/libogg/include/ogg/os_types.h b/Engine/lib/libogg/include/ogg/os_types.h index d6691b703..8bf82107e 100644 --- a/Engine/lib/libogg/include/ogg/os_types.h +++ b/Engine/lib/libogg/include/ogg/os_types.h @@ -11,7 +11,7 @@ ******************************************************************** function: #ifdef jail to whip a few platforms into the UNIX ideal. - last mod: $Id: os_types.h 17712 2010-12-03 17:10:02Z xiphmont $ + last mod: $Id: os_types.h 19098 2014-02-26 19:06:45Z giles $ ********************************************************************/ #ifndef _OS_TYPES_H @@ -24,7 +24,7 @@ #define _ogg_realloc realloc #define _ogg_free free -#if defined(_WIN32) +#if defined(_WIN32) # if defined(__CYGWIN__) # include diff --git a/Engine/lib/libogg/src/bitwise.c b/Engine/lib/libogg/src/bitwise.c index 68aca6754..145901d18 100644 --- a/Engine/lib/libogg/src/bitwise.c +++ b/Engine/lib/libogg/src/bitwise.c @@ -5,13 +5,13 @@ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * - * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2010 * + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2014 * * by the Xiph.Org Foundation http://www.xiph.org/ * * * ******************************************************************** function: packing variable sized words into an octet stream - last mod: $Id: bitwise.c 18051 2011-08-04 17:56:39Z giles $ + last mod: $Id: bitwise.c 19149 2014-05-27 16:26:23Z giles $ ********************************************************************/ @@ -187,8 +187,22 @@ static void oggpack_writecopy_helper(oggpack_buffer *b, unsigned char *ptr=(unsigned char *)source; long bytes=bits/8; + long pbytes=(b->endbit+bits)/8; bits-=bytes*8; + /* expand storage up-front */ + if(b->endbyte+pbytes>=b->storage){ + void *ret; + if(!b->ptr) goto err; + if(b->storage>b->endbyte+pbytes+BUFFER_INCREMENT) goto err; + b->storage=b->endbyte+pbytes+BUFFER_INCREMENT; + ret=_ogg_realloc(b->buffer,b->storage); + if(!ret) goto err; + b->buffer=ret; + b->ptr=b->buffer+b->endbyte; + } + + /* copy whole octets */ if(b->endbit){ int i; /* unaligned copy. Do it the hard way. */ @@ -196,23 +210,13 @@ static void oggpack_writecopy_helper(oggpack_buffer *b, w(b,(unsigned long)(ptr[i]),8); }else{ /* aligned block copy */ - if(b->endbyte+bytes+1>=b->storage){ - void *ret; - if(!b->ptr) goto err; - if(b->endbyte+bytes+BUFFER_INCREMENT>b->storage) goto err; - b->storage=b->endbyte+bytes+BUFFER_INCREMENT; - ret=_ogg_realloc(b->buffer,b->storage); - if(!ret) goto err; - b->buffer=ret; - b->ptr=b->buffer+b->endbyte; - } - memmove(b->ptr,source,bytes); b->ptr+=bytes; b->endbyte+=bytes; *b->ptr=0; - } + + /* copy trailing bits */ if(bits){ if(msb) w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits); @@ -613,9 +617,190 @@ void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){ if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n"); } +void copytest(int prefill, int copy){ + oggpack_buffer source_write; + oggpack_buffer dest_write; + oggpack_buffer source_read; + oggpack_buffer dest_read; + unsigned char *source; + unsigned char *dest; + long source_bytes,dest_bytes; + int i; + + oggpack_writeinit(&source_write); + oggpack_writeinit(&dest_write); + + for(i=0;i<(prefill+copy+7)/8;i++) + oggpack_write(&source_write,(i^0x5a)&0xff,8); + source=oggpack_get_buffer(&source_write); + source_bytes=oggpack_bytes(&source_write); + + /* prefill */ + oggpack_writecopy(&dest_write,source,prefill); + + /* check buffers; verify end byte masking */ + dest=oggpack_get_buffer(&dest_write); + dest_bytes=oggpack_bytes(&dest_write); + if(dest_bytes!=(prefill+7)/8){ + fprintf(stderr,"wrong number of bytes after prefill! %ld!=%d\n",dest_bytes,(prefill+7)/8); + exit(1); + } + oggpack_readinit(&source_read,source,source_bytes); + oggpack_readinit(&dest_read,dest,dest_bytes); + + for(i=0;i +#include #include #include @@ -236,39 +237,51 @@ int ogg_stream_destroy(ogg_stream_state *os){ /* Helpers for ogg_stream_encode; this keeps the structure and what's happening fairly clear */ -static int _os_body_expand(ogg_stream_state *os,int needed){ - if(os->body_storage<=os->body_fill+needed){ +static int _os_body_expand(ogg_stream_state *os,long needed){ + if(os->body_storage-needed<=os->body_fill){ + long body_storage; void *ret; - ret=_ogg_realloc(os->body_data,(os->body_storage+needed+1024)* - sizeof(*os->body_data)); + if(os->body_storage>LONG_MAX-needed){ + ogg_stream_clear(os); + return -1; + } + body_storage=os->body_storage+needed; + if(body_storagebody_data,body_storage*sizeof(*os->body_data)); if(!ret){ ogg_stream_clear(os); return -1; } - os->body_storage+=(needed+1024); + os->body_storage=body_storage; os->body_data=ret; } return 0; } -static int _os_lacing_expand(ogg_stream_state *os,int needed){ - if(os->lacing_storage<=os->lacing_fill+needed){ +static int _os_lacing_expand(ogg_stream_state *os,long needed){ + if(os->lacing_storage-needed<=os->lacing_fill){ + long lacing_storage; void *ret; - ret=_ogg_realloc(os->lacing_vals,(os->lacing_storage+needed+32)* - sizeof(*os->lacing_vals)); + if(os->lacing_storage>LONG_MAX-needed){ + ogg_stream_clear(os); + return -1; + } + lacing_storage=os->lacing_storage+needed; + if(lacing_storagelacing_vals,lacing_storage*sizeof(*os->lacing_vals)); if(!ret){ ogg_stream_clear(os); return -1; } os->lacing_vals=ret; - ret=_ogg_realloc(os->granule_vals,(os->lacing_storage+needed+32)* + ret=_ogg_realloc(os->granule_vals,lacing_storage* sizeof(*os->granule_vals)); if(!ret){ ogg_stream_clear(os); return -1; } os->granule_vals=ret; - os->lacing_storage+=(needed+32); + os->lacing_storage=lacing_storage; } return 0; } @@ -304,12 +317,17 @@ void ogg_page_checksum_set(ogg_page *og){ int ogg_stream_iovecin(ogg_stream_state *os, ogg_iovec_t *iov, int count, long e_o_s, ogg_int64_t granulepos){ - int bytes = 0, lacing_vals, i; + long bytes = 0, lacing_vals; + int i; if(ogg_stream_check(os)) return -1; if(!iov) return 0; - for (i = 0; i < count; ++i) bytes += (int)iov[i].iov_len; + for (i = 0; i < count; ++i){ + if(iov[i].iov_len>LONG_MAX) return -1; + if(bytes>LONG_MAX-(long)iov[i].iov_len) return -1; + bytes += (long)iov[i].iov_len; + } lacing_vals=bytes/255+1; if(os->body_returned){ diff --git a/Tools/CMake/libraries/libogg.cmake b/Tools/CMake/libraries/libogg.cmake index c68617264..655e7ce92 100644 --- a/Tools/CMake/libraries/libogg.cmake +++ b/Tools/CMake/libraries/libogg.cmake @@ -22,6 +22,21 @@ project(libogg) +include(CheckIncludeFiles) + +# Configure config_type.h +check_include_files(inttypes.h INCLUDE_INTTYPES_H) +check_include_files(stdint.h INCLUDE_STDINT_H) +check_include_files(sys/types.h INCLUDE_SYS_TYPES_H) + +set(SIZE16 int16_t) +set(USIZE16 uint16_t) +set(SIZE32 int32_t) +set(USIZE32 uint32_t) +set(SIZE64 int64_t) + +configure_file(${libDir}/libogg/include/ogg/config_types.h.in ${libDir}/libogg/include/ogg/config_types.h @ONLY) + addPath("${libDir}/libogg" REC) addInclude(${libDir}/libogg/include)