ref: 0a4cd796df5b030cb866f3f4a5e41a4b92caddf5
parent: cf218fb54929a1f54e30e2cb208a22d08b08c889
author: Ralph Giles <[email protected]>
date: Tue Sep 6 15:04:31 EDT 2022
Propagate allocation failure from ogg_sync_buffer. Instead of segfault, report OP_EFAULT if ogg_sync_buffer returns a null pointer. This allows more graceful recovery by the caller in the unlikely event of a fallible ogg_malloc call. We do check the return value elsewhere in the code, so the new checks make the code more consistent. Thanks to https://github.com/xiph/opusfile/issues/36 for reporting. Signed-off-by: Timothy B. Terriberry <[email protected]> Signed-off-by: Mark Harris <[email protected]>
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -148,6 +148,7 @@
int nbytes;
OP_ASSERT(_nbytes>0);
buffer=(unsigned char *)ogg_sync_buffer(&_of->oy,_nbytes);
+ if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
nbytes=(int)(*_of->callbacks.read)(_of->stream,buffer,_nbytes);
OP_ASSERT(nbytes<=_nbytes);
if(OP_LIKELY(nbytes>0))ogg_sync_wrote(&_of->oy,nbytes);
@@ -1527,6 +1528,7 @@
if(_initial_bytes>0){
char *buffer;
buffer=ogg_sync_buffer(&_of->oy,(long)_initial_bytes);
+ if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
memcpy(buffer,_initial_data,_initial_bytes*sizeof(*buffer));
ogg_sync_wrote(&_of->oy,(long)_initial_bytes);
}