Browse Source

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.
master
kevin 10 years ago
parent
commit
e65764d7a4
2 changed files with 16 additions and 7 deletions
  1. 15
    7
      cmAudioFile.c
  2. 1
    0
      cmAudioFile.h

+ 15
- 7
cmAudioFile.c View File

@@ -75,6 +75,7 @@ cmAudioErrRecd _cmAudioFileErrArray[] =
75 75
   { kInvalidBitWidthAfRC, "Invalid audio file bit width."},
76 76
   { kInvalidFileModeAfRC, "Invalid audio file mode."},
77 77
   { kInvalidHandleAfRC,   "Invalid audio file handle."},
78
+  { kInvalidChCountAfRC,  "Invalid channel index or count."},
78 79
   { kUnknownErrAfRC,      "Uknown audio file error."}
79 80
 };
80 81
 
@@ -696,18 +697,22 @@ cmRC_t     cmAudioFileCreate(  cmAudioFileH_t h, const cmChar_t* fn, double srat
696 697
       return rc;
697 698
 
698 699
   // all audio files are written as AIF's - if the file name is given some other extension then issue a warning
699
-  if( strlen(fn) && ((pp = cmFsPathParts(fn)) != NULL) )
700
+  if( fn!=NULL && strlen(fn) && ((pp = cmFsPathParts(fn)) != NULL) )
700 701
   {
701 702
     unsigned i;
702
-    unsigned n = strlen(pp->extStr);
703
+    unsigned n = pp->extStr==NULL ? 0 : strlen(pp->extStr);
703 704
     cmChar_t ext[n+1];
704
-    strcpy(ext,pp->extStr);
705 705
 
706
-    // convert the extension to upper case
707
-    for(i=0; i<n; ++i)
708
-      ext[i] = toupper(ext[i]);
706
+    if( pp->extStr != NULL )
707
+    {
708
+      strcpy(ext,pp->extStr);
709
+
710
+      // convert the extension to upper case
711
+      for(i=0; i<n; ++i)
712
+        ext[i] = toupper(ext[i]);
713
+    }
709 714
 
710
-    if( strcmp(ext,"AIF") && strcmp(ext,"AIFF") )
715
+    if( pp->extStr==NULL || (strcmp(ext,"AIF") && strcmp(ext,"AIFF")) )
711 716
       cmRptPrintf(p->err.rpt,"The AIF audio file '%s' is being written with a file extension other than 'AIF' or 'AIFF'.",cmStringNullGuard(fn));
712 717
       
713 718
     cmFsFreePathParts(pp);
@@ -845,6 +850,9 @@ cmRC_t _cmAudioFileReadInt( cmAudioFileH_t h, unsigned totalFrmCnt, unsigned chI
845 850
   if( rc != kOkAfRC )
846 851
     return rc;  
847 852
 
853
+  if( chIdx+chCnt > p->info.chCnt )
854
+    return _cmAudioFileError(p,kInvalidChCountAfRC);
855
+
848 856
   if( actualFrmCntPtr != NULL )
849 857
     *actualFrmCntPtr = 0;
850 858
 

+ 1
- 0
cmAudioFile.h View File

@@ -37,6 +37,7 @@ extern "C" {
37 37
     kInvalidBitWidthAfRC,
38 38
     kInvalidFileModeAfRC,
39 39
     kInvalidHandleAfRC,
40
+    kInvalidChCountAfRC,
40 41
     kUnknownErrAfRC
41 42
   };
42 43
 

Loading…
Cancel
Save