Skip to content

Commit ce7846e

Browse files
InterLinked1Friendly Automation
authored andcommitted
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
1 parent 193b7a8 commit ce7846e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

main/file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,12 @@ int ast_stream_fastforward(struct ast_filestream *fs, off_t ms)
10971097

10981098
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
10991099
{
1100+
off_t offset = ast_tellstream(fs);
1101+
if (ms * DEFAULT_SAMPLES_PER_MS > offset) {
1102+
/* Don't even bother asking the file format to seek to a negative offset... */
1103+
ast_debug(1, "Restarting, rather than seeking to negative offset %ld\n", (long) (offset - (ms * DEFAULT_SAMPLES_PER_MS)));
1104+
return ast_seekstream(fs, 0, SEEK_SET);
1105+
}
11001106
return ast_seekstream(fs, -ms * DEFAULT_SAMPLES_PER_MS, SEEK_CUR);
11011107
}
11021108

0 commit comments

Comments
 (0)