shithub: opusfile

Download patch

ref: 567165a7feb9b4e540dc9d257fd276849d660060
parent: 58b229ae9d6142f822914562e33d5d4b9d6faef1
author: James Zern <jzern@google.com>
date: Thu Dec 7 10:24:48 EST 2017

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 <tterribe@xiph.org>

--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -2597,15 +2597,14 @@
     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.*/