From dfd363e83035e506b53873da9c8f036f1c9821a1 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 16 Dec 2023 20:06:45 +0100 Subject: [PATCH] Fix integer overflow for sample duration The result is assign to a long (64-bit signed integer), but the intermediate multiplication was stored in a 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. Fixes #4536 --- server/src/main/java/com/genymobile/scrcpy/AudioCapture.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java index e3de50e639..76e2f63b39 100644 --- a/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/AudioCapture.java @@ -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) {