[opus] [PATCH 1/2] op_pcm_seek: fix int64 overflow
James Zern
jzern at google.com
Mon Nov 20 21:07:20 UTC 2017
check for overflow with a negative diff
---
src/opusfile.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/opusfile.c b/src/opusfile.c
index 72f1272..df326af 100644
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -2605,7 +2605,11 @@ int op_pcm_seek(OggOpusFile *_of,ogg_int64_t _pcm_offset){
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;
+ /*Check for overflow.*/
+ if(diff<0&&OP_UNLIKELY(OP_INT64_MAX+diff<_pcm_offset)){
+ discard_count=0;
+ }
+ else discard_count=_pcm_offset-diff;
/*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.0.448.gf294e3d99a-goog
More information about the opus
mailing list