From 66d8cf8be47bd5151b1b66fe7ce47a1a4c7d7c9f Mon Sep 17 00:00:00 2001 From: Andrew Watts Date: Wed, 24 May 2023 15:24:52 -0400 Subject: [PATCH] UB fix. enum mad_layer has no variant with a discriminator equal to zero. Using a default-initialized frame in rust causes various problems, including segfaults and inexplicable EOF errors. Initialize this field to a valid discriminator. --- simplemad_sys/libmad-src/frame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplemad_sys/libmad-src/frame.c b/simplemad_sys/libmad-src/frame.c index 0cb3d0f..b3656d4 100644 --- a/simplemad_sys/libmad-src/frame.c +++ b/simplemad_sys/libmad-src/frame.c @@ -67,7 +67,7 @@ int (*const decoder_table[3])(struct mad_stream *, struct mad_frame *) = { */ void mad_header_init(struct mad_header *header) { - header->layer = 0; + header->layer = MAD_LAYER_I; header->mode = 0; header->mode_extension = 0; header->emphasis = 0;