ref: 427d61131a1af5eed48d5428e723ab4602b56cc1
parent: 6d46f2d7f7617852bab7cbb2f7cae8350b99204e
author: Mark Harris <[email protected]>
date: Mon Dec 28 20:43:37 EST 2020
Fix use of uninitialized serialno Also do not crash if OPE_GET_SERIALNO_REQUEST is used after draining.
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -356,6 +356,11 @@
return NULL;
}
+static void stream_generate_serialno(EncStream *stream) {
+ stream->serialno = rand();
+ stream->serialno_is_set = 1;
+}
+
static void stream_destroy(EncStream *stream) {
if (stream->comment) free(stream->comment);
free(stream);
@@ -512,9 +517,7 @@
static void init_stream(OggOpusEnc *enc) {
assert(!enc->streams->stream_is_init);
- if (!enc->streams->serialno_is_set) {
- enc->streams->serialno = rand();
- }
+ if (!enc->streams->serialno_is_set) stream_generate_serialno(enc->streams);
if (enc->oggp != NULL) oggp_chain(enc->oggp, enc->streams->serialno);
else {
@@ -1071,6 +1074,11 @@
case OPE_GET_SERIALNO_REQUEST:
{
opus_int32 *value = va_arg(ap, opus_int32*);
+ if (!enc->last_stream) {
+ ret = OPE_TOO_LATE;
+ break;
+ }
+ if (!enc->last_stream->serialno_is_set) stream_generate_serialno(enc->last_stream);
*value = enc->last_stream->serialno;
}
break;