Commit 4174c26e authored by Timothy B. Terriberry's avatar Timothy B. Terriberry

Fix short-circuit test when seeking in short files

When a file is very, very short (i.e., only one packet) and uses
 end-trimming, the apparent granule position preceding the first
 sample in the first packet can underflow.
We were computing this value by subtracting the packet duration
 from the computed per-packet granule position and expecting this
 computation to always succeed.
Because it could fail in the presence of end-trimming on the first
 packet (ironically, exactly the situation where the short-circuit
 is helpful), it would leave the value uninitialized, and then use
 it in a comparison, which is undefined behavior.
The correct solution is to check for failure and force the previous
 page's granule position to 0 in this case.
parent f94a1764
Pipeline #2190 passed with stage
in 50 seconds
......@@ -2358,8 +2358,19 @@ static int op_pcm_seek_page(OggOpusFile *_of,
For very small files (with all of the data in a single page,
generally 1 second or less), we can loop them continuously
without seeking at all.*/
-op_get_packet_duration(_of->op[0].packet,_of->op[0].bytes))<0) {
/*We validate/sanitize the per-packet timestamps, so the only way
we should fail to calculate a granule position for the
previous page is if the first page with completed packets in
the stream is also the last, and end-trimming causes the
apparent granule position preceding the first sample in the
first packet to underflow.
The starting PCM offset is then 0 by spec mandate (see also:
/*Don't call op_decode_clear(), because it will dump our
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment