[FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
From: Thomas Volkert tho...@homer-conferencing.com Make it more readable and display an error message in case an invalid header is detected (the current version just returns AVERROR_INVALIDDATA) --- libavformat/wavdec.c | 31 ++- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 8a7f84b..b2f6964 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -248,7 +248,7 @@ static int wav_read_header(AVFormatContext *s) { int64_t size, av_uninit(data_size); int64_t sample_count = 0; -int rf64; +int rf64 = 0; uint32_t tag; AVIOContext *pb = s-pb; AVStream *st = NULL; @@ -260,17 +260,30 @@ static int wav_read_header(AVFormatContext *s) wav-smv_data_ofs = -1; -/* check RIFF header */ +/* read chunk ID */ tag = avio_rl32(pb); - -rf64 = tag == MKTAG('R', 'F', '6', '4'); -wav-rifx = tag == MKTAG('R', 'I', 'F', 'X'); -if (!rf64 !wav-rifx tag != MKTAG('R', 'I', 'F', 'F')) +switch (tag) { +case MKTAG('R', 'I', 'F', 'F'): +break; +case MKTAG('R', 'I', 'F', 'X'): +wav-rifx = 1; +break; +case MKTAG('R', 'F', '6', '4'): +rf64 = 1; +break; +default: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; -avio_rl32(pb); /* file size */ -tag = avio_rl32(pb); -if (tag != MKTAG('W', 'A', 'V', 'E')) +} + +/* read chunk size */ +avio_rl32(pb); + +/* read format */ +if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) { +av_log(s, AV_LOG_ERROR, invalid format in RIFF header\n); return AVERROR_INVALIDDATA; +} if (rf64) { if (avio_rl32(pb) != MKTAG('d', 's', '6', '4')) -- 1.9.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On 12/19/2014 9:09 PM, Thomas Volkert wrote: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); I'm sure printing possibly non-printable chars is a great idea. Nothing could go wrong. Use 0x%X or something please. - Derek ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On Fri, Dec 19, 2014 at 08:15:26PM +, Derek Buitenhuis wrote: On 12/19/2014 9:09 PM, Thomas Volkert wrote: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); I'm sure printing possibly non-printable chars is a great idea. Nothing could go wrong. Use 0x%X or something please. hmm, i suggest av_get_codec_tag_string() [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is dangerous to be right in matters on which the established authorities are wrong. -- Voltaire signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
From: Thomas Volkert tho...@homer-conferencing.com Make it more readable and display an error message in case an invalid header is detected (the current version just returns AVERROR_INVALIDDATA) --- libavformat/wavdec.c | 31 ++- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 8a7f84b..b2f6964 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -248,7 +248,7 @@ static int wav_read_header(AVFormatContext *s) { int64_t size, av_uninit(data_size); int64_t sample_count = 0; -int rf64; +int rf64 = 0; uint32_t tag; AVIOContext *pb = s-pb; AVStream *st = NULL; @@ -260,17 +260,30 @@ static int wav_read_header(AVFormatContext *s) wav-smv_data_ofs = -1; -/* check RIFF header */ +/* read chunk ID */ tag = avio_rl32(pb); - -rf64 = tag == MKTAG('R', 'F', '6', '4'); -wav-rifx = tag == MKTAG('R', 'I', 'F', 'X'); -if (!rf64 !wav-rifx tag != MKTAG('R', 'I', 'F', 'F')) +switch (tag) { +case MKTAG('R', 'I', 'F', 'F'): +break; +case MKTAG('R', 'I', 'F', 'X'): +wav-rifx = 1; +break; +case MKTAG('R', 'F', '6', '4'): +rf64 = 1; +break; +default: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; -avio_rl32(pb); /* file size */ -tag = avio_rl32(pb); -if (tag != MKTAG('W', 'A', 'V', 'E')) +} + +/* read chunk size */ +avio_rl32(pb); + +/* read format */ +if (avio_rl32(pb) != MKTAG('W', 'A', 'V', 'E')) { +av_log(s, AV_LOG_ERROR, invalid format in RIFF header\n); return AVERROR_INVALIDDATA; +} if (rf64) { if (avio_rl32(pb) != MKTAG('d', 's', '6', '4')) -- 1.9.1 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On 12/19/2014 09:57 PM, Thomas Volkert wrote: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; Some remainung tabs - please, remove when commit. Best regards, Thomas. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On Fri, Dec 19, 2014 at 09:58:48PM +0100, Thomas Volkert wrote: On 12/19/2014 09:57 PM, Thomas Volkert wrote: +av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; Some remainung tabs - please, remove when commit. applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many things microsoft did are stupid, but not doing something just because microsoft did it is even more stupid. If everything ms did were stupid they would be bankrupt already. signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On 19/12/14 7:00 PM, Michael Niedermayer wrote: On Fri, Dec 19, 2014 at 09:58:48PM +0100, Thomas Volkert wrote: On 12/19/2014 09:57 PM, Thomas Volkert wrote: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; Some remainung tabs - please, remove when commit. applied thanks This didn't address Derek's comments. It's not using av_get_codec_tag_string() or something like 0x%X. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] wavdec: refactor wav_read_header()
On 12/19/2014 11:03 PM, James Almer wrote: On 19/12/14 7:00 PM, Michael Niedermayer wrote: On Fri, Dec 19, 2014 at 09:58:48PM +0100, Thomas Volkert wrote: On 12/19/2014 09:57 PM, Thomas Volkert wrote: + av_log(s, AV_LOG_ERROR, invalid start code %c%c%c%c in RIFF header\n, tag 0xFF, (tag 8) 0xFF, (tag 16) 0xFF, (tag 24) 0xFF); return AVERROR_INVALIDDATA; Some remainung tabs - please, remove when commit. applied thanks This didn't address Derek's comments. It's not using av_get_codec_tag_string() or something like 0x%X. I forgot to commit before resending the patch :-( Best regards, Thomas. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel