comparison utils.c @ 6008:2e702728eea8 libavformat

Validate AVCodecTag vs CodecID. Patch by Francesco Lavra, francescolavra interfree it
author cehoyos
date Tue, 18 May 2010 19:23:29 +0000
parents f9eb8adfdb9e
children ee42a04b24f2
comparison
equal deleted inserted replaced
6007:f9eb8adfdb9e 6008:2e702728eea8
2571 return ret; 2571 return ret;
2572 } 2572 }
2573 return 0; 2573 return 0;
2574 } 2574 }
2575 2575
2576 static int validate_codec_tag(AVFormatContext *s, AVStream *st)
2577 {
2578 const AVCodecTag *avctag;
2579 int n;
2580 enum CodecID id = CODEC_ID_NONE;
2581 unsigned int tag = 0;
2582
2583 /**
2584 * Check that tag + id is in the table
2585 * If neither is in the table -> OK
2586 * If tag is in the table with another id -> FAIL
2587 * If id is in the table with another tag -> FAIL unless strict < normal
2588 */
2589 for (n = 0; s->oformat->codec_tag[n]; n++) {
2590 avctag = s->oformat->codec_tag[n];
2591 while (avctag->id != CODEC_ID_NONE) {
2592 if (ff_toupper4(avctag->tag) == ff_toupper4(st->codec->codec_tag)) {
2593 id = avctag->id;
2594 if (id == st->codec->codec_id)
2595 return 1;
2596 }
2597 if (avctag->id == st->codec->codec_id)
2598 tag = avctag->tag;
2599 avctag++;
2600 }
2601 }
2602 if (id != CODEC_ID_NONE)
2603 return 0;
2604 if (tag && (st->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL))
2605 return 0;
2606 return 1;
2607 }
2608
2576 int av_write_header(AVFormatContext *s) 2609 int av_write_header(AVFormatContext *s)
2577 { 2610 {
2578 int ret, i; 2611 int ret, i;
2579 AVStream *st; 2612 AVStream *st;
2580 2613
2613 break; 2646 break;
2614 } 2647 }
2615 2648
2616 if(s->oformat->codec_tag){ 2649 if(s->oformat->codec_tag){
2617 if(st->codec->codec_tag){ 2650 if(st->codec->codec_tag){
2618 //FIXME 2651 if (!validate_codec_tag(s, st)) {
2619 //check that tag + id is in the table 2652 av_log(s, AV_LOG_ERROR,
2620 //if neither is in the table -> OK 2653 "Tag 0x%08x incompatible with output codec\n",
2621 //if tag is in the table with another id -> FAIL 2654 st->codec->codec_tag);
2622 //if id is in the table with another tag -> FAIL unless strict < ? 2655 return AVERROR_INVALIDDATA;
2656 }
2623 }else 2657 }else
2624 st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id); 2658 st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id);
2625 } 2659 }
2626 2660
2627 if(s->oformat->flags & AVFMT_GLOBALHEADER && 2661 if(s->oformat->flags & AVFMT_GLOBALHEADER &&