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
   { kInvalidBitWidthAfRC, "Invalid audio file bit width."},
75
   { kInvalidBitWidthAfRC, "Invalid audio file bit width."},
76
   { kInvalidFileModeAfRC, "Invalid audio file mode."},
76
   { kInvalidFileModeAfRC, "Invalid audio file mode."},
77
   { kInvalidHandleAfRC,   "Invalid audio file handle."},
77
   { kInvalidHandleAfRC,   "Invalid audio file handle."},
78
+  { kInvalidChCountAfRC,  "Invalid channel index or count."},
78
   { kUnknownErrAfRC,      "Uknown audio file error."}
79
   { kUnknownErrAfRC,      "Uknown audio file error."}
79
 };
80
 };
80
 
81
 
696
       return rc;
697
       return rc;
697
 
698
 
698
   // all audio files are written as AIF's - if the file name is given some other extension then issue a warning
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
     unsigned i;
702
     unsigned i;
702
-    unsigned n = strlen(pp->extStr);
703
+    unsigned n = pp->extStr==NULL ? 0 : strlen(pp->extStr);
703
     cmChar_t ext[n+1];
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
       cmRptPrintf(p->err.rpt,"The AIF audio file '%s' is being written with a file extension other than 'AIF' or 'AIFF'.",cmStringNullGuard(fn));
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
     cmFsFreePathParts(pp);
718
     cmFsFreePathParts(pp);
845
   if( rc != kOkAfRC )
850
   if( rc != kOkAfRC )
846
     return rc;  
851
     return rc;  
847
 
852
 
853
+  if( chIdx+chCnt > p->info.chCnt )
854
+    return _cmAudioFileError(p,kInvalidChCountAfRC);
855
+
848
   if( actualFrmCntPtr != NULL )
856
   if( actualFrmCntPtr != NULL )
849
     *actualFrmCntPtr = 0;
857
     *actualFrmCntPtr = 0;
850
 
858
 

+ 1
- 0
cmAudioFile.h View File

37
     kInvalidBitWidthAfRC,
37
     kInvalidBitWidthAfRC,
38
     kInvalidFileModeAfRC,
38
     kInvalidFileModeAfRC,
39
     kInvalidHandleAfRC,
39
     kInvalidHandleAfRC,
40
+    kInvalidChCountAfRC,
40
     kUnknownErrAfRC
41
     kUnknownErrAfRC
41
   };
42
   };
42
 
43
 

Loading…
Cancel
Save