[FFmpeg-devel] [PATCH] mpegencts: Fix overflow in cbr mode period calculations

Michael Niedermayer michaelni at gmx.at
Sat Nov 28 04:22:47 CET 2015


On Fri, Nov 27, 2015 at 09:25:52PM +0200, Timo Teräs wrote:
> ts->mux_rate is int (signed 32-bit) type. The period calculations
> will start to overflow when mux_rate > 5mbps. This fixes overflows
> by using av_rescale().
> 
> Fixes #5044.
> 
> Signed-off-by: Timo Teräs <timo.teras at iki.fi>
> ---
>  libavformat/mpegtsenc.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index 468bad4..8c0987c 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -852,12 +852,9 @@ static int mpegts_write_header(AVFormatContext *s)
>          ts_st = pcr_st->priv_data;
>  
>      if (ts->mux_rate > 1) {
> -        service->pcr_packet_period = (ts->mux_rate * ts->pcr_period) /
> -                                     (TS_PACKET_SIZE * 8 * 1000);
> -        ts->sdt_packet_period      = (ts->mux_rate * SDT_RETRANS_TIME) /
> -                                     (TS_PACKET_SIZE * 8 * 1000);
> -        ts->pat_packet_period      = (ts->mux_rate * PAT_RETRANS_TIME) /
> -                                     (TS_PACKET_SIZE * 8 * 1000);
> +        service->pcr_packet_period = av_rescale(ts->pcr_period,   ts->mux_rate, TS_PACKET_SIZE * 8 * 1000);
> +        ts->sdt_packet_period      = av_rescale(SDT_RETRANS_TIME, ts->mux_rate, TS_PACKET_SIZE * 8 * 1000);
> +        ts->pat_packet_period      = av_rescale(PAT_RETRANS_TIME, ts->mux_rate, TS_PACKET_SIZE * 8 * 1000);

The previous code did round down ensuring that the period was
smaller than the requested limit if inexact
see av_rescale_rnd() or int64_t could be used too


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored answer#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151128/3a13f185/attachment.sig>


More information about the ffmpeg-devel mailing list