filesize = avio_size(s->pb);
pos_max = filesize - 1;
do{
- pos_max -= step;
+ pos_max = FFMAX(0, pos_max - step);
ts_max = ff_read_timestamp(s, stream_index, &pos_max, pos_max + step, read_timestamp);
step += step;
- }while(ts_max == AV_NOPTS_VALUE && pos_max >= step);
+ }while(ts_max == AV_NOPTS_VALUE && pos_max > 0);
if (ts_max == AV_NOPTS_VALUE)
return -1;