[Asterisk-code-review] file.c: Prevent formats from seeking negative offsets. (asterisk[master])
Friendly Automation
asteriskteam at digium.com
Tue Apr 26 19:24:58 CDT 2022
Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/18122 )
Change subject: file.c: Prevent formats from seeking negative offsets.
......................................................................
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
---
M main/file.c
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Benjamin Keith Ford: Looks good to me, but someone else must approve
Friendly Automation: Approved for Submit
diff --git a/main/file.c b/main/file.c
index a6cd300..8bb40da 100644
--- a/main/file.c
+++ b/main/file.c
@@ -1097,6 +1097,12 @@
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);
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18122
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ia53f2623f57898f4b8e5c894b968b01e95426967
Gerrit-Change-Number: 18122
Gerrit-PatchSet: 2
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220426/acfc73fc/attachment.html>
More information about the asterisk-code-review
mailing list