[asterisk-commits] mjordan: branch 10 r362152 - in /branches/10: ./ formats/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 16 14:39:38 CDT 2012
Author: mjordan
Date: Mon Apr 16 14:39:32 2012
New Revision: 362152
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362152
Log:
Check for IO stream failures in various format's truncate/seek operations
For the formats that support seek and/or truncate operations, many of
the C library calls used to determine or set the current position indicator
in the file stream were not being checked. In some situations, if an error
occurred, a negative value would be returned from the library call. This
could then be interpreted inappropriately as positional data.
This patch checks the return values from these library calls before
using them in subsequent operations.
(issue ASTERISK-19655)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/1863/
........
Merged revisions 362151 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/10/ (props changed)
branches/10/formats/format_g719.c
branches/10/formats/format_g723.c
branches/10/formats/format_g729.c
branches/10/formats/format_gsm.c
branches/10/formats/format_h263.c
branches/10/formats/format_h264.c
branches/10/formats/format_ilbc.c
branches/10/formats/format_pcm.c
branches/10/formats/format_siren14.c
branches/10/formats/format_siren7.c
branches/10/formats/format_sln.c
branches/10/formats/format_vox.c
branches/10/formats/format_wav.c
branches/10/formats/format_wav_gsm.c
Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/10/formats/format_g719.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_g719.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_g719.c (original)
+++ branches/10/formats/format_g719.c Mon Apr 16 14:39:32 2012
@@ -82,11 +82,20 @@
sample_offset = SAMPLES_TO_BYTES(sample_offset);
- cur = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- fseeko(fs->f, 0, SEEK_END);
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- max = ftello(fs->f);
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
if (whence == SEEK_SET)
offset = sample_offset;
@@ -106,7 +115,18 @@
static int g719trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ return ftruncate(fd, cur);
}
static off_t g719tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_g723.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_g723.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_g723.c (original)
+++ branches/10/formats/format_g723.c Mon Apr 16 14:39:32 2012
@@ -118,10 +118,19 @@
static int g723_trunc(struct ast_filestream *fs)
{
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for g723 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g723 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
/* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
- return -1;
- return 0;
+ return ftruncate(fd, cur);
}
static off_t g723_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_g729.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_g729.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_g729.c (original)
+++ branches/10/formats/format_g729.c Mon Apr 16 14:39:32 2012
@@ -113,10 +113,19 @@
static int g729_trunc(struct ast_filestream *fs)
{
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for g729 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g729 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
/* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
- return -1;
- return 0;
+ return ftruncate(fd, cur);
}
static off_t g729_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_gsm.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_gsm.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_gsm.c (original)
+++ branches/10/formats/format_gsm.c Mon Apr 16 14:39:32 2012
@@ -108,20 +108,33 @@
static int gsm_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t offset=0,min,cur,max,distance;
-
- min = 0;
- cur = ftello(fs->f);
- fseeko(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
+ off_t offset = 0, min = 0, cur, max, distance;
+
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
/* have to fudge to frame here, so not fully to sample */
- distance = (sample_offset/GSM_SAMPLES) * GSM_FRAME_SIZE;
- if(whence == SEEK_SET)
+ distance = (sample_offset / GSM_SAMPLES) * GSM_FRAME_SIZE;
+ if (whence == SEEK_SET) {
offset = distance;
- else if(whence == SEEK_CUR || whence == SEEK_FORCECUR)
+ } else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
offset = distance + cur;
- else if(whence == SEEK_END)
+ } else if (whence == SEEK_END) {
offset = max - distance;
+ }
+
/* Always protect against seeking past the begining. */
offset = (offset < min)?min:offset;
if (whence != SEEK_FORCECUR) {
@@ -140,13 +153,31 @@
static int gsm_trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for gsm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in gsm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t gsm_tell(struct ast_filestream *fs)
{
off_t offset = ftello(fs->f);
- return (offset/GSM_FRAME_SIZE)*GSM_SAMPLES;
+
+ if (offset < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine offset for gsm filestream %p: %s\n", fs, strerror(errno));
+ return 0;
+ }
+
+ return (offset / GSM_FRAME_SIZE) * GSM_SAMPLES;
}
static struct ast_format_def gsm_f = {
Modified: branches/10/formats/format_h263.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_h263.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_h263.c (original)
+++ branches/10/formats/format_h263.c Mon Apr 16 14:39:32 2012
@@ -147,10 +147,19 @@
static int h263_trunc(struct ast_filestream *fs)
{
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h263 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in h263 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
/* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
- return -1;
- return 0;
+ return ftruncate(fd, cur);
}
static off_t h263_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_h264.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_h264.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_h264.c (original)
+++ branches/10/formats/format_h264.c Mon Apr 16 14:39:32 2012
@@ -140,10 +140,19 @@
static int h264_trunc(struct ast_filestream *fs)
{
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h264 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in h264 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
/* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
- return -1;
- return 0;
+ return ftruncate(fd, cur);
}
static off_t h264_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_ilbc.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_ilbc.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_ilbc.c (original)
+++ branches/10/formats/format_ilbc.c Mon Apr 16 14:39:32 2012
@@ -111,10 +111,19 @@
static int ilbc_trunc(struct ast_filestream *fs)
{
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for iLBC filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in iLBC filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
/* Truncate file to current length */
- if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
- return -1;
- return 0;
+ return ftruncate(fd, cur);
}
static off_t ilbc_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_pcm.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_pcm.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_pcm.c (original)
+++ branches/10/formats/format_pcm.c Mon Apr 16 14:39:32 2012
@@ -105,9 +105,20 @@
off_t cur, max, offset = 0;
int ret = -1; /* assume error */
- cur = ftello(fs->f);
- fseeko(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in pcm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of pcm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in pcm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
switch (whence) {
case SEEK_SET:
@@ -151,7 +162,18 @@
static int pcm_trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int cur, fd;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for pcm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in pcm filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t pcm_tell(struct ast_filestream *fs)
@@ -374,7 +396,7 @@
/* XXX check this, probably incorrect */
static int au_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t min, max, cur;
+ off_t min = AU_HEADER_SIZE, max, cur;
long offset = 0, bytes;
if (fs->fmt->format.id == AST_FORMAT_G722)
@@ -382,10 +404,20 @@
else
bytes = sample_offset;
- min = AU_HEADER_SIZE;
- cur = ftello(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of au filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in au filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
if (whence == SEEK_SET)
offset = bytes + min;
@@ -406,8 +438,21 @@
static int au_trunc(struct ast_filestream *fs)
{
- if (ftruncate(fileno(fs->f), ftell(fs->f)))
- return -1;
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for au filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in au filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ if (ftruncate(fd, cur)) {
+ return -1;
+ }
return update_header(fs->f);
}
Modified: branches/10/formats/format_siren14.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_siren14.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_siren14.c (original)
+++ branches/10/formats/format_siren14.c Mon Apr 16 14:39:32 2012
@@ -82,11 +82,20 @@
sample_offset = SAMPLES_TO_BYTES(sample_offset);
- cur = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- fseeko(fs->f, 0, SEEK_END);
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- max = ftello(fs->f);
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
if (whence == SEEK_SET)
offset = sample_offset;
@@ -106,7 +115,19 @@
static int siren14trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren14 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t siren14tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_siren7.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_siren7.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_siren7.c (original)
+++ branches/10/formats/format_siren7.c Mon Apr 16 14:39:32 2012
@@ -82,11 +82,20 @@
sample_offset = SAMPLES_TO_BYTES(sample_offset);
- cur = ftello(fs->f);
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren7 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- fseeko(fs->f, 0, SEEK_END);
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of siren7 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
- max = ftello(fs->f);
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in siren7 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
if (whence == SEEK_SET)
offset = sample_offset;
@@ -106,7 +115,19 @@
static int siren7trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for siren7 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in siren7 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t siren7tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_sln.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_sln.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_sln.c (original)
+++ branches/10/formats/format_sln.c Mon Apr 16 14:39:32 2012
@@ -72,13 +72,25 @@
static int slinear_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t offset=0,min,cur,max;
-
- min = 0;
+ off_t offset=0, min = 0, cur, max;
+
sample_offset <<= 1;
- cur = ftello(fs->f);
- fseeko(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
+
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of sln filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in sln filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
if (whence == SEEK_SET)
offset = sample_offset;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -95,7 +107,19 @@
static int slinear_trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for sln filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in sln filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);
}
static off_t slinear_tell(struct ast_filestream *fs)
Modified: branches/10/formats/format_vox.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_vox.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_vox.c (original)
+++ branches/10/formats/format_vox.c Mon Apr 16 14:39:32 2012
@@ -78,32 +78,54 @@
static int vox_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t offset=0,min,cur,max,distance;
-
- min = 0;
- cur = ftello(fs->f);
- fseeko(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
-
- /* have to fudge to frame here, so not fully to sample */
- distance = sample_offset/2;
- if(whence == SEEK_SET)
- offset = distance;
- else if(whence == SEEK_CUR || whence == SEEK_FORCECUR)
- offset = distance + cur;
- else if(whence == SEEK_END)
- offset = max - distance;
- if (whence != SEEK_FORCECUR) {
- offset = (offset > max)?max:offset;
- offset = (offset < min)?min:offset;
- }
- return fseeko(fs->f, offset, SEEK_SET);
+ off_t offset = 0, min = 0, cur, max, distance;
+
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ /* have to fudge to frame here, so not fully to sample */
+ distance = sample_offset/2;
+ if (whence == SEEK_SET) {
+ offset = distance;
+ } else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
+ offset = distance + cur;
+ } else if (whence == SEEK_END) {
+ offset = max - distance;
+ }
+ if (whence != SEEK_FORCECUR) {
+ offset = (offset > max)?max:offset;
+ offset = (offset < min)?min:offset;
+ }
+ return fseeko(fs->f, offset, SEEK_SET);
}
static int vox_trunc(struct ast_filestream *fs)
{
- return ftruncate(fileno(fs->f), ftello(fs->f));
-}
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for vox filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in vox filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ return ftruncate(fd, cur);}
static off_t vox_tell(struct ast_filestream *fs)
{
Modified: branches/10/formats/format_wav.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_wav.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_wav.c (original)
+++ branches/10/formats/format_wav.c Mon Apr 16 14:39:32 2012
@@ -41,6 +41,8 @@
/* Portions of the conversion code are by guido at sienanet.it */
#define WAV_BUF_SIZE 320
+
+#define WAV_HEADER_SIZE 44
struct wav_desc { /* format-specific parameters */
int hz;
@@ -452,13 +454,25 @@
static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t min, max, cur, offset = 0, samples;
+ off_t min = WAV_HEADER_SIZE, max, cur, offset = 0, samples;
samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */
- min = 44; /* wav header is 44 bytes */
- cur = ftello(fs->f);
- fseeko(fs->f, 0, SEEK_END);
- max = ftello(fs->f);
+
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in wav filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of wav filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in wav filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
if (whence == SEEK_SET)
offset = samples + min;
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -475,8 +489,21 @@
static int wav_trunc(struct ast_filestream *fs)
{
- if (ftruncate(fileno(fs->f), ftello(fs->f)))
- return -1;
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for wav filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in wav filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ if (ftruncate(fd, cur)) {
+ return -1;
+ }
return update_header(fs->f);
}
Modified: branches/10/formats/format_wav_gsm.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/formats/format_wav_gsm.c?view=diff&rev=362152&r1=362151&r2=362152
==============================================================================
--- branches/10/formats/format_wav_gsm.c (original)
+++ branches/10/formats/format_wav_gsm.c Mon Apr 16 14:39:32 2012
@@ -475,13 +475,25 @@
static int wav_seek(struct ast_filestream *fs, off_t sample_offset, int whence)
{
- off_t offset=0, distance, max;
+ off_t offset = 0, min = MSGSM_DATA_OFFSET, distance, max, cur;
struct wavg_desc *s = (struct wavg_desc *)fs->_private;
- off_t min = MSGSM_DATA_OFFSET;
- off_t cur = ftello(fs->f);
- fseek(fs->f, 0, SEEK_END);
- max = ftello(fs->f); /* XXX ideally, should round correctly */
+ if ((cur = ftello(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ if (fseeko(fs->f, 0, SEEK_END) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to seek to end of WAV filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
+ /* XXX ideally, should round correctly */
+ if ((max = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine max position in WAV filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+
/* Compute the distance in bytes, rounded to the block size */
distance = (sample_offset/MSGSM_SAMPLES) * MSGSM_FRAME_SIZE;
if (whence == SEEK_SET)
@@ -511,8 +523,21 @@
static int wav_trunc(struct ast_filestream *fs)
{
- if (ftruncate(fileno(fs->f), ftello(fs->f)))
- return -1;
+ int fd;
+ off_t cur;
+
+ if ((fd = fileno(fs->f)) < 0) {
+ ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for WAV filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ if ((cur = ftello(fs->f) < 0)) {
+ ast_log(AST_LOG_WARNING, "Unable to determine current position in WAV filestream %p: %s\n", fs, strerror(errno));
+ return -1;
+ }
+ /* Truncate file to current length */
+ if (ftruncate(fd, cur)) {
+ return -1;
+ }
return update_header(fs->f);
}
More information about the asterisk-commits
mailing list