cmAudioFile.h/c : Fixed crash bug in cmAudioFilecreate() caused by using a file name without and extension.

_cmAudioFileReadInt() now returns in error instead of asserting when an invalid input channel count is encountered.
This commit is contained in:
kevin 2014-01-30 23:35:25 -08:00
parent d863299265
commit e65764d7a4
2 changed files with 16 additions and 7 deletions

View File

@ -75,6 +75,7 @@ cmAudioErrRecd _cmAudioFileErrArray[] =
{ kInvalidBitWidthAfRC, "Invalid audio file bit width."}, { kInvalidBitWidthAfRC, "Invalid audio file bit width."},
{ kInvalidFileModeAfRC, "Invalid audio file mode."}, { kInvalidFileModeAfRC, "Invalid audio file mode."},
{ kInvalidHandleAfRC, "Invalid audio file handle."}, { kInvalidHandleAfRC, "Invalid audio file handle."},
{ kInvalidChCountAfRC, "Invalid channel index or count."},
{ kUnknownErrAfRC, "Uknown audio file error."} { kUnknownErrAfRC, "Uknown audio file error."}
}; };
@ -696,18 +697,22 @@ cmRC_t cmAudioFileCreate( cmAudioFileH_t h, const cmChar_t* fn, double srat
return rc; return rc;
// all audio files are written as AIF's - if the file name is given some other extension then issue a warning // all audio files are written as AIF's - if the file name is given some other extension then issue a warning
if( strlen(fn) && ((pp = cmFsPathParts(fn)) != NULL) ) if( fn!=NULL && strlen(fn) && ((pp = cmFsPathParts(fn)) != NULL) )
{ {
unsigned i; unsigned i;
unsigned n = strlen(pp->extStr); unsigned n = pp->extStr==NULL ? 0 : strlen(pp->extStr);
cmChar_t ext[n+1]; cmChar_t ext[n+1];
if( pp->extStr != NULL )
{
strcpy(ext,pp->extStr); strcpy(ext,pp->extStr);
// convert the extension to upper case // convert the extension to upper case
for(i=0; i<n; ++i) for(i=0; i<n; ++i)
ext[i] = toupper(ext[i]); ext[i] = toupper(ext[i]);
}
if( strcmp(ext,"AIF") && strcmp(ext,"AIFF") ) if( pp->extStr==NULL || (strcmp(ext,"AIF") && strcmp(ext,"AIFF")) )
cmRptPrintf(p->err.rpt,"The AIF audio file '%s' is being written with a file extension other than 'AIF' or 'AIFF'.",cmStringNullGuard(fn)); cmRptPrintf(p->err.rpt,"The AIF audio file '%s' is being written with a file extension other than 'AIF' or 'AIFF'.",cmStringNullGuard(fn));
cmFsFreePathParts(pp); cmFsFreePathParts(pp);
@ -845,6 +850,9 @@ cmRC_t _cmAudioFileReadInt( cmAudioFileH_t h, unsigned totalFrmCnt, unsigned chI
if( rc != kOkAfRC ) if( rc != kOkAfRC )
return rc; return rc;
if( chIdx+chCnt > p->info.chCnt )
return _cmAudioFileError(p,kInvalidChCountAfRC);
if( actualFrmCntPtr != NULL ) if( actualFrmCntPtr != NULL )
*actualFrmCntPtr = 0; *actualFrmCntPtr = 0;

View File

@ -37,6 +37,7 @@ extern "C" {
kInvalidBitWidthAfRC, kInvalidBitWidthAfRC,
kInvalidFileModeAfRC, kInvalidFileModeAfRC,
kInvalidHandleAfRC, kInvalidHandleAfRC,
kInvalidChCountAfRC,
kUnknownErrAfRC kUnknownErrAfRC
}; };