Revision b7c40744 libavformat/avidec.c

View differences:

libavformat/avidec.c
43 43

  
44 44
    int prefix;                       ///< normally 'd'<<8 + 'c' or 'w'<<8 + 'b'
45 45
    int prefix_count;
46
    uint32_t pal[256];
47
    int has_pal;
46 48
} AVIStream;
47 49

  
48 50
typedef struct {
......
684 686
            size= ast->remaining;
685 687
        av_get_packet(pb, pkt, size);
686 688

  
689
        if(ast->has_pal && pkt->data && pkt->size<(unsigned)INT_MAX/2){
690
            ast->has_pal=0;
691
            pkt->size += 4*256;
692
            pkt->data = av_realloc(pkt->data, pkt->size + FF_INPUT_BUFFER_PADDING_SIZE);
693
            if(pkt->data)
694
                memcpy(pkt->data + pkt->size - 4*256, ast->pal, 4*256);
695
        }
696

  
687 697
        if (ENABLE_DV_DEMUXER && avi->dv_demux) {
688 698
            dstr = pkt->destruct;
689 699
            size = dv_produce_packet(avi->dv_demux, pkt,
......
781 791
                goto resync;
782 792
          }
783 793

  
794
          if (d[2] == 'p' && d[3] == 'c' && size<=4*256+4) {
795
                int k = get_byte(pb);
796
                int last = (k + get_byte(pb) - 1) & 0xFF;
797

  
798
                get_le16(pb); //flags
799

  
800
                for (; k <= last; k++)
801
                    ast->pal[k] = get_be32(pb)>>8;// b + (g << 8) + (r << 16);
802
                ast->has_pal= 1;
803
                goto resync;
804
          } else
784 805
          if(   ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) ||
785 806
                d[2]*256+d[3] == ast->prefix /*||
786 807
                (d[2] == 'd' && d[3] == 'c') ||
......
807 828
            goto resync;
808 829
          }
809 830
        }
810
        /* palette changed chunk */
811
        if (   d[0] >= '0' && d[0] <= '9'
812
            && d[1] >= '0' && d[1] <= '9'
813
            && ((d[2] == 'p' && d[3] == 'c'))
814
            && n < s->nb_streams && i + size <= avi->fsize) {
815

  
816
            AVStream *st;
817
            int first, clr, flags, k, p;
818

  
819
            st = s->streams[n];
820

  
821
            first = get_byte(pb);
822
            clr = get_byte(pb);
823
            if(!clr) /* all 256 colors used */
824
                clr = 256;
825
            flags = get_le16(pb);
826
            p = 4;
827
            for (k = first; k < clr + first; k++) {
828
                int r, g, b;
829
                r = get_byte(pb);
830
                g = get_byte(pb);
831
                b = get_byte(pb);
832
                    get_byte(pb);
833
                st->codec->palctrl->palette[k] = b + (g << 8) + (r << 16);
834
            }
835
            st->codec->palctrl->palette_changed = 1;
836
            goto resync;
837
        }
838

  
839 831
    }
840 832

  
841 833
    return -1;

Also available in: Unified diff