You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

  1. From 427d61131a1af5eed48d5428e723ab4602b56cc1 Mon Sep 17 00:00:00 2001
  2. From: Mark Harris <mark.hsj@gmail.com>
  3. Date: Tue, 29 Dec 2020 01:43:37 -0800
  4. Subject: [PATCH] Fix use of uninitialized serialno
  5. Also do not crash if OPE_GET_SERIALNO_REQUEST is used after draining.
  6. ---
  7. src/opusenc.c | 14 +++++++++++---
  8. 1 file changed, 11 insertions(+), 3 deletions(-)
  9. --- a/src/opusenc.c
  10. +++ b/src/opusenc.c
  11. @@ -356,6 +356,11 @@ fail:
  12. return NULL;
  13. }
  14. +static void stream_generate_serialno(EncStream *stream) {
  15. + stream->serialno = rand();
  16. + stream->serialno_is_set = 1;
  17. +}
  18. +
  19. static void stream_destroy(EncStream *stream) {
  20. if (stream->comment) free(stream->comment);
  21. free(stream);
  22. @@ -512,9 +517,7 @@ int ope_encoder_deferred_init_with_mappi
  23. static void init_stream(OggOpusEnc *enc) {
  24. assert(!enc->streams->stream_is_init);
  25. - if (!enc->streams->serialno_is_set) {
  26. - enc->streams->serialno = rand();
  27. - }
  28. + if (!enc->streams->serialno_is_set) stream_generate_serialno(enc->streams);
  29. if (enc->oggp != NULL) oggp_chain(enc->oggp, enc->streams->serialno);
  30. else {
  31. @@ -1071,6 +1074,11 @@ int ope_encoder_ctl(OggOpusEnc *enc, int
  32. case OPE_GET_SERIALNO_REQUEST:
  33. {
  34. opus_int32 *value = va_arg(ap, opus_int32*);
  35. + if (!enc->last_stream) {
  36. + ret = OPE_TOO_LATE;
  37. + break;
  38. + }
  39. + if (!enc->last_stream->serialno_is_set) stream_generate_serialno(enc->last_stream);
  40. *value = enc->last_stream->serialno;
  41. }
  42. break;