From 567165a7feb9b4e540dc9d257fd276849d660060 Mon Sep 17 00:00:00 2001 From: James Zern Date: Thu, 7 Dec 2017 15:24:48 -0800 Subject: [PATCH] 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 --- src/opusfile.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/opusfile.c b/src/opusfile.c index 72f1272..140503e 100644 --- a/src/opusfile.c +++ b/src/opusfile.c @@ -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.*/ -- 2.1.4