Skip to content

Commit 0a4cd79

Browse files
committed
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 #36 for reporting. Signed-off-by: Timothy B. Terriberry <[email protected]> Signed-off-by: Mark Harris <[email protected]>
1 parent cf218fb commit 0a4cd79

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/opusfile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static int op_get_data(OggOpusFile *_of,int _nbytes){
148148
int nbytes;
149149
OP_ASSERT(_nbytes>0);
150150
buffer=(unsigned char *)ogg_sync_buffer(&_of->oy,_nbytes);
151+
if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
151152
nbytes=(int)(*_of->callbacks.read)(_of->stream,buffer,_nbytes);
152153
OP_ASSERT(nbytes<=_nbytes);
153154
if(OP_LIKELY(nbytes>0))ogg_sync_wrote(&_of->oy,nbytes);
@@ -1527,6 +1528,7 @@ static int op_open1(OggOpusFile *_of,
15271528
if(_initial_bytes>0){
15281529
char *buffer;
15291530
buffer=ogg_sync_buffer(&_of->oy,(long)_initial_bytes);
1531+
if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
15301532
memcpy(buffer,_initial_data,_initial_bytes*sizeof(*buffer));
15311533
ogg_sync_wrote(&_of->oy,(long)_initial_bytes);
15321534
}

0 commit comments

Comments
 (0)