From c1df9b5b070cedf072e670a994d2db738109a20c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeremy=20Lain=C3=A9?= Date: Wed, 3 Dec 2025 22:55:07 +0100 Subject: [PATCH] file.c: Ensure opening a stream opens at most one file The functions used to stream files eventually end up calling into `filehelper(.., ACTION_OPEN)` which takes care of iterating over supported extensions and opening the first existing file. To do this, `filehelper` uses two nested loops: - An outer loop over the supported file formats. - An inner loop over the possible extensions for that format. We need to break out of both loops as soon as a file was successfully opened. Otherwise if a file exists in multiple formats (e.g `foo.wav` and `foo.alaw`) both files will be opened successively. Resolves: #1625 --- main/file.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main/file.c b/main/file.c index c71e80d167..ed203cea76 100644 --- a/main/file.c +++ b/main/file.c @@ -678,6 +678,11 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c } ast_free(fn); } + + /* If we have successfully opened a file, we are done. */ + if (action == ACTION_OPEN && res == 1) { + break; + } } AST_RWLIST_UNLOCK(&formats); return res;