[FFmpeg-cvslog] avformat/subtitles: binary search seeking.
Clément Bœsch
u at pkh.me
Tue Sep 10 07:31:46 CEST 2013
On Tue, Sep 10, 2013 at 01:53:16AM +0200, Alexander Strasser wrote:
> Hi Clément!
>
> On 2013-09-08 12:57 +0200, Clément Bœsch wrote:
> > ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Sun Sep 8 12:36:57 2013 +0200| [b1319e14e3b068045a9147244f3edd5863abe6fd] | committer: Clément Bœsch
> >
> > avformat/subtitles: binary search seeking.
> >
> > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b1319e14e3b068045a9147244f3edd5863abe6fd
> > ---
> >
> > libavformat/subtitles.c | 50 ++++++++++++++++++++++++++++++++++-------------
> > 1 file changed, 36 insertions(+), 14 deletions(-)
> >
> > diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> > index b796f40..d460797 100644
> > --- a/libavformat/subtitles.c
> > +++ b/libavformat/subtitles.c
> > @@ -1,5 +1,5 @@
> > /*
> > - * Copyright (c) 2012 Clément Bœsch
> > + * Copyright (c) 2012-2013 Clément Bœsch <u pkh me>
> > *
> > * This file is part of FFmpeg.
> > *
> > @@ -94,6 +94,28 @@ int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt)
> > return 0;
> > }
> >
> > +static int search_sub_ts(const FFDemuxSubtitlesQueue *q, int64_t ts)
> > +{
> > + int s1 = 0, s2 = q->nb_subs - 1;
> > +
> > + if (s2 < s1)
> > + return AVERROR(ERANGE);
> > +
> > + for (;;) {
> > + int mid;
> > +
> > + if (s1 == s2)
> > + return s1;
> > + if (s1 == s2 - 1)
> > + return q->subs[s1].pts <= q->subs[s2].pts ? s1 : s2;
> > + mid = (s1 + s2) / 2;
> ^^^^^^^
> If I am not mistaken this can cause a signed overflow, if I am
> able to get enought subtitle packets in the queue.
AFAICT this can only happen if you don't use the API to insert subtitles.
The number of subtitles is limited to INT_MAX/sizeof(AVPacket); see
ff_subtitles_queue_insert().
[...]
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-cvslog/attachments/20130910/430b08ea/attachment.asc>
More information about the ffmpeg-cvslog
mailing list