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
This commit is contained in:
Naveen Albert 2022-03-01 01:29:43 +00:00 committed by Friendly Automation
parent f97386bd54
commit 237defce8a
1 changed files with 6 additions and 0 deletions

View File

@ -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);
}