shithub: opusfile

Download patch

ref: 0e4b81e15f2ccb8cf437f055e50d1a989237d3ec
parent: f6ed2a8818e34a0ca6495b453d3b812d9fe3d046
author: Timothy B. Terriberry <[email protected]>
date: Sat Aug 24 06:55:07 EDT 2013

Replace 0x7FFFFFFF by new OP_INT32_MAX.

OP_INT32_MIN and OP_INT32_MAX were added in commit 97917914.
This fixes at least one bug, since one of the (extremely unlikely)
 overflow checks had an extra F in it.

--- a/src/http.c
+++ b/src/http.c
@@ -977,11 +977,11 @@
 static opus_int32 op_time_diff_ms(const struct timeb *_end,
  const struct timeb *_start){
   opus_int64 dtime;
-  dtime=_end->time-_start->time;
+  dtime=_end->time-(opus_int64)_start->time;
   OP_ASSERT(_end->millitm<1000);
   OP_ASSERT(_start->millitm<1000);
-  if(OP_UNLIKELY(dtime>(0x7FFFFFFF-1000)/1000))return 0x7FFFFFFF;
-  if(OP_UNLIKELY(dtime<(-0x7FFFFFFF+999)/1000))return -0x7FFFFFFF-1;
+  if(OP_UNLIKELY(dtime>(OP_INT32_MAX-1000)/1000))return OP_INT32_MAX;
+  if(OP_UNLIKELY(dtime<(OP_INT32_MIN+1000)/1000))return OP_INT32_MIN;
   return (opus_int32)dtime*1000+_end->millitm-_start->millitm;
 }
 
@@ -2800,7 +2800,7 @@
           /*Unless there's a bug, we should be able to convert
              (next_pos,next_end) into valid (_pos,_chunk_size) parameters.*/
           OP_ASSERT(next_end<0
-           ||next_end-next_pos>=0&&next_end-next_pos<=0x7FFFFFFF);
+           ||next_end-next_pos>=0&&next_end-next_pos<=OP_INT32_MAX);
           ret=op_http_conn_open_pos(_stream,_conn,next_pos,
            next_end<0?-1:(opus_int32)(next_end-next_pos));
           if(OP_UNLIKELY(ret<0))return OP_EREAD;
--- a/src/opusfile.c
+++ b/src/opusfile.c
@@ -1774,11 +1774,13 @@
   /*These rates are absurd, but let's handle them anyway.*/
   if(OP_UNLIKELY(_bytes>(OP_INT64_MAX-(_samples>>1))/(48000*8))){
     ogg_int64_t den;
-    if(OP_UNLIKELY(_bytes/(0x7FFFFFFFF/(48000*8))>=_samples))return 0x7FFFFFFF;
+    if(OP_UNLIKELY(_bytes/(OP_INT32_MAX/(48000*8))>=_samples)){
+      return OP_INT32_MAX;
+    }
     den=_samples/(48000*8);
     return (opus_int32)((_bytes+(den>>1))/den);
   }
-  if(OP_UNLIKELY(_samples<=0))return 0x7FFFFFFF;
+  if(OP_UNLIKELY(_samples<=0))return OP_INT32_MAX;
   /*This can't actually overflow in normal operation: even with a pre-skip of
      545 2.5 ms frames with 8 streams running at 1282*8+1 bytes per packet
      (1275 byte frames + Opus framing overhead + Ogg lacing values), that all
@@ -1786,7 +1788,8 @@
     The only way to get bitrates larger than that is with excessive Opus
      padding, more encoded streams than output channels, or lots and lots of
      Ogg pages with no packets on them.*/
-  return (opus_int32)OP_MIN((_bytes*48000*8+(_samples>>1))/_samples,0x7FFFFFFF);
+  return (opus_int32)OP_MIN((_bytes*48000*8+(_samples>>1))/_samples,
+   OP_INT32_MAX);
 }
 
 opus_int32 op_bitrate(OggOpusFile *_of,int _li){
@@ -2458,7 +2461,7 @@
   if(_pcm_offset<=link->head.pre_skip)skip=0;
   else skip=OP_MAX(_pcm_offset-80*48,0);
   OP_ASSERT(_pcm_offset-skip>=0);
-  OP_ASSERT(_pcm_offset-skip<0x7FFFFFFF-120*48);
+  OP_ASSERT(_pcm_offset-skip<OP_INT32_MAX-120*48);
   /*Skip packets until we find one with samples past our skip target.*/
   for(;;){
     op_count=_of->op_count;
@@ -2484,7 +2487,7 @@
   /*We skipped too far.
     Either the timestamps were illegal or there was a hole in the data.*/
   if(diff>skip)return OP_EBADLINK;
-  OP_ASSERT(_pcm_offset-diff<0x7FFFFFFF);
+  OP_ASSERT(_pcm_offset-diff<OP_INT32_MAX);
   /*TODO: If there are further holes/illegal timestamps, we still won't decode
      to the correct sample.
     However, at least op_pcm_tell() will report the correct value immediately