2
1

0001-Propagate-allocation-failure-from-ogg_sync_buffer.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From 0a4cd796df5b030cb866f3f4a5e41a4b92caddf5 Mon Sep 17 00:00:00 2001
  2. From: Ralph Giles <giles@thaumas.net>
  3. Date: Tue, 6 Sep 2022 19:04:31 -0700
  4. Subject: [PATCH] Propagate allocation failure from ogg_sync_buffer.
  5. Instead of segfault, report OP_EFAULT if ogg_sync_buffer returns
  6. a null pointer. This allows more graceful recovery by the caller
  7. in the unlikely event of a fallible ogg_malloc call.
  8. We do check the return value elsewhere in the code, so the new
  9. checks make the code more consistent.
  10. Thanks to https://github.com/xiph/opusfile/issues/36 for reporting.
  11. Signed-off-by: Timothy B. Terriberry <tterribe@xiph.org>
  12. Signed-off-by: Mark Harris <mark.hsj@gmail.com>
  13. [Retrieved from:
  14. https://github.com/xiph/opusfile/commit/0a4cd796df5b030cb866f3f4a5e41a4b92caddf5]
  15. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  16. ---
  17. src/opusfile.c | 2 ++
  18. 1 file changed, 2 insertions(+)
  19. diff --git a/src/opusfile.c b/src/opusfile.c
  20. index ca219b2..3c3c81e 100644
  21. --- a/src/opusfile.c
  22. +++ b/src/opusfile.c
  23. @@ -148,6 +148,7 @@ static int op_get_data(OggOpusFile *_of,int _nbytes){
  24. int nbytes;
  25. OP_ASSERT(_nbytes>0);
  26. buffer=(unsigned char *)ogg_sync_buffer(&_of->oy,_nbytes);
  27. + if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
  28. nbytes=(int)(*_of->callbacks.read)(_of->stream,buffer,_nbytes);
  29. OP_ASSERT(nbytes<=_nbytes);
  30. if(OP_LIKELY(nbytes>0))ogg_sync_wrote(&_of->oy,nbytes);
  31. @@ -1527,6 +1528,7 @@ static int op_open1(OggOpusFile *_of,
  32. if(_initial_bytes>0){
  33. char *buffer;
  34. buffer=ogg_sync_buffer(&_of->oy,(long)_initial_bytes);
  35. + if(OP_UNLIKELY(buffer==NULL))return OP_EFAULT;
  36. memcpy(buffer,_initial_data,_initial_bytes*sizeof(*buffer));
  37. ogg_sync_wrote(&_of->oy,(long)_initial_bytes);
  38. }