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.

78 lines
2.9 KiB

  1. From 6d46f2d7f7617852bab7cbb2f7cae8350b99204e Mon Sep 17 00:00:00 2001
  2. From: Mark Harris <mark.hsj@gmail.com>
  3. Date: Mon, 28 Dec 2020 17:01:39 -0800
  4. Subject: [PATCH] Fix use of uninitialized fields
  5. enc->streams->end_granule used uninitialized in encode_buffer() if the
  6. stream contains no audio (opusenc_example /dev/null out.opus).
  7. enc->frame_size_request used uninitialized in encode_buffer() if the
  8. frame size was not explicitly set.
  9. enc->callbacks used uninitialized if the encoder is created with
  10. ope_encoder_create_callbacks() and callbacks is NULL.
  11. ---
  12. src/opusenc.c | 23 +++++++++++++++++------
  13. 1 file changed, 17 insertions(+), 6 deletions(-)
  14. --- a/src/opusenc.c
  15. +++ b/src/opusenc.c
  16. @@ -361,8 +361,7 @@ static void stream_destroy(EncStream *st
  17. free(stream);
  18. }
  19. -/* Create a new OggOpus file (callback-based). */
  20. -OggOpusEnc *ope_encoder_create_callbacks(const OpusEncCallbacks *callbacks, void *user_data,
  21. +static OggOpusEnc *ope_encoder_create_callbacks_impl(const OpusEncCallbacks *callbacks, void *user_data,
  22. OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error) {
  23. OggOpusEnc *enc=NULL;
  24. int ret;
  25. @@ -395,11 +394,11 @@ OggOpusEnc *ope_encoder_create_callbacks
  26. enc->oggp = NULL;
  27. /* Not initializing anything is an unrecoverable error. */
  28. enc->unrecoverable = family == -1 ? OPE_TOO_LATE : 0;
  29. - enc->pull_api = 0;
  30. enc->packet_callback = NULL;
  31. enc->rate = rate;
  32. enc->channels = channels;
  33. enc->frame_size = 960;
  34. + enc->frame_size_request = OPUS_FRAMESIZE_20_MS;
  35. enc->decision_delay = 96000;
  36. enc->max_ogg_delay = 48000;
  37. enc->chaining_keyframe = NULL;
  38. @@ -447,8 +446,12 @@ OggOpusEnc *ope_encoder_create_callbacks
  39. if (callbacks != NULL)
  40. {
  41. enc->callbacks = *callbacks;
  42. + enc->pull_api = 0;
  43. + } else {
  44. + enc->pull_api = 1;
  45. }
  46. enc->streams->user_data = user_data;
  47. + enc->streams->end_granule = 0;
  48. if (error) *error = OPE_OK;
  49. return enc;
  50. fail:
  51. @@ -462,11 +465,19 @@ fail:
  52. return NULL;
  53. }
  54. +/* Create a new OggOpus stream (callback-based). */
  55. +OggOpusEnc *ope_encoder_create_callbacks(const OpusEncCallbacks *callbacks, void *user_data,
  56. + OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error) {
  57. + if (callbacks == NULL) {
  58. + if (error) *error = OPE_BAD_ARG;
  59. + return NULL;
  60. + }
  61. + return ope_encoder_create_callbacks_impl(callbacks, user_data, comments, rate, channels, family, error);
  62. +}
  63. +
  64. /* Create a new OggOpus stream, pulling one page at a time. */
  65. OggOpusEnc *ope_encoder_create_pull(OggOpusComments *comments, opus_int32 rate, int channels, int family, int *error) {
  66. - OggOpusEnc *enc = ope_encoder_create_callbacks(NULL, NULL, comments, rate, channels, family, error);
  67. - if (enc) enc->pull_api = 1;
  68. - return enc;
  69. + return ope_encoder_create_callbacks_impl(NULL, NULL, comments, rate, channels, family, error);
  70. }
  71. int ope_encoder_deferred_init_with_mapping(OggOpusEnc *enc, int family, int streams,