Commit 567165a7 authored by James Zern's avatar James Zern Committed by Timothy B. Terriberry

op_pcm_seek: Fix int64 overflow

Calculate discard_count directly with op_granpos_diff. this works
because _pcm_offset == (target_gp - pcm_start) and diff == (gp -
pcm_start).
Signed-off-by: Timothy B. Terriberry's avatarTimothy B. Terriberry <tterribe@xiph.org>
parent 58b229ae
......@@ -2597,15 +2597,14 @@ int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset){
ogg_int64_t gp;
gp=_of->prev_packet_gp;
if(OP_LIKELY(gp!=-1)){
int nbuffered;
ogg_int64_t discard_count;
int nbuffered;
nbuffered=OP_MAX(_of->od_buffer_size-_of->od_buffer_pos,0);
OP_ALWAYS_TRUE(!op_granpos_add(&gp,gp,-nbuffered));
/*We do _not_ add cur_discard_count to gp.
Otherwise the total amount to discard could grow without bound, and it
would be better just to do a full seek.*/
if(OP_LIKELY(!op_granpos_diff(&diff,gp,pcm_start))){
ogg_int64_t discard_count;
discard_count=_pcm_offset-diff;
if(OP_LIKELY(!op_granpos_diff(&discard_count,target_gp,gp))){
/*We use a threshold of 90 ms instead of 80, since 80 ms is the
_minimum_ we would have discarded after a full seek.
Assuming 20 ms frames (the default), we'd discard 90 ms on average.*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment