Skip to content

Commit

Permalink
file.c: Prevent formats from seeking negative offsets.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
InterLinked1 authored and Friendly Automation committed Apr 27, 2022
1 parent 193b7a8 commit ce7846e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit ce7846e

Please sign in to comment.