Ticket #587: ffmpeg-resample2-rate-overflow.patch

File ffmpeg-resample2-rate-overflow.patch, 834 bytes (added by Jim Radford, 15 years ago)

Patch to avoid an overflow in av_resample's rate calculations

  • ffmpeg-0.8.5/libavcodec/resample2.c

     
    207208    memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM));
    208209    c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1];
    209210
    210     c->src_incr= out_rate;
    211     c->ideal_dst_incr= c->dst_incr= in_rate * phase_count;
     211    int64_t dst_incr = (int64_t)in_rate * phase_count, src_incr = out_rate;
     212    int64_t gcd = av_gcd(dst_incr, src_incr);
     213    if (dst_incr / gcd > INT_MAX || src_incr / gcd > INT_MAX)
     214        goto error;
     215
     216    c->src_incr= src_incr / gcd;
     217    c->ideal_dst_incr= c->dst_incr= dst_incr / gcd;
    212218    c->index= -phase_count*((c->filter_length-1)/2);
    213219
    214220    return c;