From ea02bc368518e3d2b952c9f27db48f414d667bc9 Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Tue, 1 Mar 2022 01:29:43 +0000 Subject: [PATCH] file.c: Prevent formats from seeking negative offsets. Currently, if a user uses an application like ControlPlayback to try to rewind a file past the beginning, this can throw warnings when the file format (e.g. PCM) tries to seek to a negative offset. Instead of letting file formats try (and fail) to seek a negative offset, we instead now catch this in the rewind function to ensure that we never seek an offset less than 0. This prevents legitimate user actions from triggering warnings from any particular file formats. ASTERISK-29943 #close Change-Id: Ia53f2623f57898f4b8e5c894b968b01e95426967 --- main/file.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main/file.c b/main/file.c index a6cd3008fa..8bb40daf98 100644 --- a/main/file.c +++ b/main/file.c @@ -1097,6 +1097,12 @@ int ast_stream_fastforward(struct ast_filestream *fs, off_t ms) int ast_stream_rewind(struct ast_filestream *fs, off_t ms) { + off_t offset = ast_tellstream(fs); + if (ms * DEFAULT_SAMPLES_PER_MS > offset) { + /* Don't even bother asking the file format to seek to a negative offset... */ + ast_debug(1, "Restarting, rather than seeking to negative offset %ld\n", (long) (offset - (ms * DEFAULT_SAMPLES_PER_MS))); + return ast_seekstream(fs, 0, SEEK_SET); + } return ast_seekstream(fs, -ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR); }