[asterisk-commits] russell: branch 1.6.2 r315258 - in /branches/1.6.2: ./ formats/format_wav.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 25 14:31:48 CDT 2011


Author: russell
Date: Mon Apr 25 14:31:44 2011
New Revision: 315258

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=315258
Log:
Merged revisions 315257 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r315257 | russell | 2011-04-25 14:28:41 -0500 (Mon, 25 Apr 2011) | 10 lines
  
  Be more flexible with unknown chunks in wav files.
  
  This patch makes format_wav ignore unknown chunks instead of erroring
  out on them.
  
  (closes issue #18306)
  Reported by: jhirsch
  Patches:
        wav_skip_unknown_blocks.diff uploaded by jhirsch (license 1156)
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/formats/format_wav.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: branches/1.6.2/formats/format_wav.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/formats/format_wav.c?view=diff&rev=315258&r1=315257&r2=315258
==============================================================================
--- branches/1.6.2/formats/format_wav.c (original)
+++ branches/1.6.2/formats/format_wav.c Mon Apr 25 14:31:44 2011
@@ -70,13 +70,68 @@
 #endif
 
 
-static int check_header(FILE *f)
-{
-	int type, size, formtype;
-	int fmt, hsize;
+static int check_header_fmt(FILE *f, int hsize)
+{
 	short format, chans, bysam, bisam;
 	int bysec;
 	int freq;
+	if (hsize < 16) {
+		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
+		return -1;
+	}
+	if (fread(&format, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (format)\n");
+		return -1;
+	}
+	if (ltohs(format) != 1) {
+		ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
+		return -1;
+	}
+	if (fread(&chans, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (format)\n");
+		return -1;
+	}
+	if (ltohs(chans) != 1) {
+		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
+		return -1;
+	}
+	if (fread(&freq, 1, 4, f) != 4) {
+		ast_log(LOG_WARNING, "Read failed (freq)\n");
+		return -1;
+	}
+	if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
+		ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
+		return -1;
+	}
+	/* Ignore the byte frequency */
+	if (fread(&bysec, 1, 4, f) != 4) {
+		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
+		return -1;
+	}
+	/* Check bytes per sample */
+	if (fread(&bysam, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
+		return -1;
+	}
+	if (ltohs(bysam) != 2) {
+		ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
+		return -1;
+	}
+	if (fread(&bisam, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
+		return -1;
+	}
+	/* Skip any additional header */
+	if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
+		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
+		return -1;
+	}
+	return 0;
+}
+
+static int check_header(FILE *f)
+{
+	int type, size, formtype;
 	int data;
 	if (fread(&type, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (type)\n");
@@ -97,69 +152,6 @@
 	}
 	if (memcmp(&formtype, "WAVE", 4)) {
 		ast_log(LOG_WARNING, "Does not contain WAVE\n");
-		return -1;
-	}
-	if (fread(&fmt, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (fmt)\n");
-		return -1;
-	}
-	if (memcmp(&fmt, "fmt ", 4)) {
-		ast_log(LOG_WARNING, "Does not say fmt\n");
-		return -1;
-	}
-	if (fread(&hsize, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (formtype)\n");
-		return -1;
-	}
-	if (ltohl(hsize) < 16) {
-		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
-		return -1;
-	}
-	if (fread(&format, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (format)\n");
-		return -1;
-	}
-	if (ltohs(format) != 1) {
-		ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
-		return -1;
-	}
-	if (fread(&chans, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (format)\n");
-		return -1;
-	}
-	if (ltohs(chans) != 1) {
-		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
-		return -1;
-	}
-	if (fread(&freq, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (freq)\n");
-		return -1;
-	}
-	if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
-		ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
-		return -1;
-	}
-	/* Ignore the byte frequency */
-	if (fread(&bysec, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
-		return -1;
-	}
-	/* Check bytes per sample */
-	if (fread(&bysam, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
-		return -1;
-	}
-	if (ltohs(bysam) != 2) {
-		ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
-		return -1;
-	}
-	if (fread(&bisam, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
-		return -1;
-	}
-	/* Skip any additional header */
-	if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
-		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
 		return -1;
 	}
 	/* Skip any facts and get the first data block */
@@ -169,23 +161,25 @@
 	    
 	    /* Begin data chunk */
 	    if (fread(&buf, 1, 4, f) != 4) {
-			ast_log(LOG_WARNING, "Read failed (data)\n");
+			ast_log(LOG_WARNING, "Read failed (block header format)\n");
 			return -1;
 	    }
 	    /* Data has the actual length of data in it */
 	    if (fread(&data, 1, 4, f) != 4) {
-			ast_log(LOG_WARNING, "Read failed (data)\n");
+			ast_log(LOG_WARNING, "Read failed (block '%.4s' header length)\n", buf);
 			return -1;
 	    }
 	    data = ltohl(data);
+		if (memcmp(&buf, "fmt ", 4) == 0) {
+			if (check_header_fmt(f, data))
+				return -1;
+			continue;
+		}
 	    if(memcmp(buf, "data", 4) == 0 ) 
 			break;
-	    if(memcmp(buf, "fact", 4) != 0 ) {
-			ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
-			return -1;
-	    }
+		ast_log(LOG_DEBUG, "Skipping unknown block '%.4s'\n", buf);
 	    if (fseek(f,data,SEEK_CUR) == -1 ) {
-			ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
+			ast_log(LOG_WARNING, "Failed to skip '%.4s' block: %d\n", buf, data);
 			return -1;
 	    }
 	}




More information about the asterisk-commits mailing list