From 163ecc2522991001336515ba191de3085b22af8b Mon Sep 17 00:00:00 2001 From: Tom Sullivan Date: Fri, 1 Jul 2022 13:39:51 +1000 Subject: [PATCH] Avoid possible infinite loop due to chunk ordering Properly re-read the chunk ID when iterating through subsequent chunks. This avoids an infinite loop in the case where the `data` chunk doesn't immediately follow the `fmt ` chunk. --- src/audio/wav_io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/audio/wav_io.c b/src/audio/wav_io.c index 38deab0..01d6647 100644 --- a/src/audio/wav_io.c +++ b/src/audio/wav_io.c @@ -106,6 +106,7 @@ bool wav_io_load(const char* filename, AudioBuffer** result) { while (memcmp(found_chunk_id, "data", 4) != 0) { const uint32_t chunk_size = fread_uint32(file); fread_and_discard(chunk_size, file); + fread(found_chunk_id, 4, 1, file); } const uint32_t chunk_size = fread_uint32(file);