ref: d669790560446e366ee4e3d3b0d8ad98dd579098
parent: 2ab13b78d8d45bc54829d5ac568bcb6d63d8d99d
author: Timothy B. Terriberry <tterribe@xiph.org>
date: Mon Sep 2 13:23:58 EDT 2013
Fix a granpos calculation we assumed couldn't fail. It was only guaranteed to work in the seekable case. Thanks to Radio Stadtfilter 96.3Mhz for sending a stream which triggered this failure.
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -2519,9 +2519,17 @@
_gp=links[_li].pcm_end;
}
if(OP_LIKELY(op_granpos_cmp(_gp,links[_li].pcm_start)>0)){
- OP_ALWAYS_TRUE(!op_granpos_diff(&delta,_gp,links[_li].pcm_start));
+ if(OP_UNLIKELY(op_granpos_diff(&delta,_gp,links[_li].pcm_start)<0)){
+ /*This means an unseekable stream claimed to have a page from more than
+ 2 billion days after we joined.*/
+ OP_ASSERT(!_of->seekable);
+ return OP_INT64_MAX;
+ }
if(delta<links[_li].head.pre_skip)delta=0;
else delta-=links[_li].head.pre_skip;
+ /*In the seekable case, _gp was limited by pcm_end.
+ In the unseekable case, pcm_offset should be 0.*/
+ OP_ASSERT(pcm_offset<=OP_INT64_MAX-delta);
pcm_offset+=delta;
}
return pcm_offset;