[opus] [PATCH] op_pcm_seek: fix int64 overflow
James Zern
jzern at google.com
Thu Dec 7 23:24:48 UTC 2017
calculate discard_count directly with op_granpos_diff. this works
because _pcm_offset == (target_gp - pcm_start) and diff == (gp -
pcm_start).
---
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.15.1.424.g9478a66081-goog
More information about the opus
mailing list