Skip to content

Commit

Permalink
Fix integer overflow for audio packet duration
Browse files Browse the repository at this point in the history
The result is assigned to a long (64-bit signed integer), but the
intermediate multiplication was stored in an int (32-bit signed
integer).

This value is only used as a fallback when no timestamp could be
retrieved, that's why it did not cause too much harm so far.

Fixes #4536 <#4536>
  • Loading branch information
rom1v committed Dec 16, 2023
1 parent 4cd61b5 commit ec41896
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public int read(ByteBuffer directBuffer, MediaCodec.BufferInfo outBufferInfo) {
pts = nextPts;
}

long durationUs = r * 1000000 / (CHANNELS * BYTES_PER_SAMPLE * SAMPLE_RATE);
long durationUs = r * 1000000L / (CHANNELS * BYTES_PER_SAMPLE * SAMPLE_RATE);
nextPts = pts + durationUs;

if (previousPts != 0 && pts < previousPts + ONE_SAMPLE_US) {
Expand Down

0 comments on commit ec41896

Please sign in to comment.