decoder/flac: validate the sample rate when scanning the tag
Don't calculate the song duration when the sample rate is 0 (division by zero crash).
This commit is contained in:
		
							
								
								
									
										1
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NEWS
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | |||||||
| ver 0.16.4 (2010/??/??) | ver 0.16.4 (2010/??/??) | ||||||
| * decoder: | * decoder: | ||||||
|   - ffmpeg: workaround for semantic API change in recent ffmpeg versions |   - ffmpeg: workaround for semantic API change in recent ffmpeg versions | ||||||
|  |   - flac: validate the sample rate when scanning the tag | ||||||
|  |  | ||||||
|  |  | ||||||
| ver 0.16.3 (2011/06/04) | ver 0.16.3 (2011/06/04) | ||||||
|   | |||||||
| @@ -224,7 +224,8 @@ flac_tag_apply_metadata(struct tag *tag, const char *track, | |||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
| 	case FLAC__METADATA_TYPE_STREAMINFO: | 	case FLAC__METADATA_TYPE_STREAMINFO: | ||||||
| 		tag->time = flac_duration(&block->data.stream_info); | 		if (block->data.stream_info.sample_rate > 0) | ||||||
|  | 			tag->time = flac_duration(&block->data.stream_info); | ||||||
| 		break; | 		break; | ||||||
|  |  | ||||||
| 	default: | 	default: | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
| #ifndef MPD_FLAC_METADATA_H | #ifndef MPD_FLAC_METADATA_H | ||||||
| #define MPD_FLAC_METADATA_H | #define MPD_FLAC_METADATA_H | ||||||
|  |  | ||||||
|  | #include <assert.h> | ||||||
| #include <stdbool.h> | #include <stdbool.h> | ||||||
| #include <FLAC/metadata.h> | #include <FLAC/metadata.h> | ||||||
|  |  | ||||||
| @@ -29,6 +30,8 @@ struct replay_gain_info; | |||||||
| static inline unsigned | static inline unsigned | ||||||
| flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info) | flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info) | ||||||
| { | { | ||||||
|  | 	assert(stream_info->sample_rate > 0); | ||||||
|  |  | ||||||
| 	return (stream_info->total_samples + stream_info->sample_rate - 1) / | 	return (stream_info->total_samples + stream_info->sample_rate - 1) / | ||||||
| 		stream_info->sample_rate; | 		stream_info->sample_rate; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann