mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-31 10:47:18 +00:00 
			
		
		
		
	Merged revisions 315258 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r315258 | russell | 2011-04-25 14:31:44 -0500 (Mon, 25 Apr 2011) | 17 lines 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) ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@315259 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
		| @@ -71,48 +71,12 @@ struct wav_desc {	/* format-specific parameters */ | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| static int check_header(FILE *f, int hz) | static int check_header_fmt(FILE *f, int hsize, int hz) | ||||||
| { | { | ||||||
| 	int type, size, formtype; |  | ||||||
| 	int fmt, hsize; |  | ||||||
| 	short format, chans, bysam, bisam; | 	short format, chans, bysam, bisam; | ||||||
| 	int bysec; | 	int bysec; | ||||||
| 	int freq; | 	int freq; | ||||||
| 	int data; | 	if (hsize < 16) { | ||||||
| 	if (fread(&type, 1, 4, f) != 4) { |  | ||||||
| 		ast_log(LOG_WARNING, "Read failed (type)\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	if (fread(&size, 1, 4, f) != 4) { |  | ||||||
| 		ast_log(LOG_WARNING, "Read failed (size)\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	size = ltohl(size); |  | ||||||
| 	if (fread(&formtype, 1, 4, f) != 4) { |  | ||||||
| 		ast_log(LOG_WARNING, "Read failed (formtype)\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	if (memcmp(&type, "RIFF", 4)) { |  | ||||||
| 		ast_log(LOG_WARNING, "Does not begin with RIFF\n"); |  | ||||||
| 		return -1; |  | ||||||
| 	} |  | ||||||
| 	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)); | 		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize)); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
| @@ -165,6 +129,34 @@ static int check_header(FILE *f, int hz) | |||||||
| 		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 ); | 		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 ); | ||||||
| 		return -1; | 		return -1; | ||||||
| 	} | 	} | ||||||
|  | 	return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static int check_header(FILE *f, int hz) | ||||||
|  | { | ||||||
|  | 	int type, size, formtype; | ||||||
|  | 	int data; | ||||||
|  | 	if (fread(&type, 1, 4, f) != 4) { | ||||||
|  | 		ast_log(LOG_WARNING, "Read failed (type)\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 	if (fread(&size, 1, 4, f) != 4) { | ||||||
|  | 		ast_log(LOG_WARNING, "Read failed (size)\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 	size = ltohl(size); | ||||||
|  | 	if (fread(&formtype, 1, 4, f) != 4) { | ||||||
|  | 		ast_log(LOG_WARNING, "Read failed (formtype)\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 	if (memcmp(&type, "RIFF", 4)) { | ||||||
|  | 		ast_log(LOG_WARNING, "Does not begin with RIFF\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 	if (memcmp(&formtype, "WAVE", 4)) { | ||||||
|  | 		ast_log(LOG_WARNING, "Does not contain WAVE\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
| 	/* Skip any facts and get the first data block */ | 	/* Skip any facts and get the first data block */ | ||||||
| 	for(;;) | 	for(;;) | ||||||
| 	{  | 	{  | ||||||
| @@ -172,23 +164,25 @@ static int check_header(FILE *f, int hz) | |||||||
| 	     | 	     | ||||||
| 	    /* Begin data chunk */ | 	    /* Begin data chunk */ | ||||||
| 	    if (fread(&buf, 1, 4, f) != 4) { | 	    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; | 			return -1; | ||||||
| 	    } | 	    } | ||||||
| 	    /* Data has the actual length of data in it */ | 	    /* Data has the actual length of data in it */ | ||||||
| 	    if (fread(&data, 1, 4, f) != 4) { | 	    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; | 			return -1; | ||||||
| 	    } | 	    } | ||||||
| 	    data = ltohl(data); | 	    data = ltohl(data); | ||||||
|  | 		if (memcmp(&buf, "fmt ", 4) == 0) { | ||||||
|  | 			if (check_header_fmt(f, data, hz)) | ||||||
|  | 				return -1; | ||||||
|  | 			continue; | ||||||
|  | 		} | ||||||
| 	    if(memcmp(buf, "data", 4) == 0 )  | 	    if(memcmp(buf, "data", 4) == 0 )  | ||||||
| 			break; | 			break; | ||||||
| 	    if(memcmp(buf, "fact", 4) != 0 ) { | 		ast_log(LOG_DEBUG, "Skipping unknown block '%.4s'\n", buf); | ||||||
| 			ast_log(LOG_WARNING, "Unknown block - not fact or data\n"); |  | ||||||
| 			return -1; |  | ||||||
| 	    } |  | ||||||
| 	    if (fseek(f,data,SEEK_CUR) == -1 ) { | 	    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; | 			return -1; | ||||||
| 	    } | 	    } | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user