diff mbox series

[FFmpeg-devel,1/7] avdevice/pulse_audio_enc: Use av_rescale() to avoid integer overflow

Message ID 20240523011758.2434580-1-michael@niedermayer.cc
State Accepted
Commit 6f52b64bcc345842a88a40ddf3873559f1160e34
Headers show
Series [FFmpeg-devel,1/7] avdevice/pulse_audio_enc: Use av_rescale() to avoid integer overflow | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Michael Niedermayer May 23, 2024, 1:17 a.m. UTC
Fixes: CID1503075 Unintentional integer overflow

Sponsored-by: Sovereign Tech Fund
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavdevice/pulse_audio_enc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer June 1, 2024, 12:21 a.m. UTC | #1
On Thu, May 23, 2024 at 03:17:52AM +0200, Michael Niedermayer wrote:
> Fixes: CID1503075 Unintentional integer overflow
> 
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavdevice/pulse_audio_enc.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)

will apply remaining patches of patchset (1-6)

[...]
diff mbox series

Patch

diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index 3e2cc91f697..80136d1e20c 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -471,10 +471,11 @@  static av_cold int pulse_write_header(AVFormatContext *h)
     s->nonblocking = (h->flags & AVFMT_FLAG_NONBLOCK);
 
     if (s->buffer_duration) {
-        int64_t bytes = s->buffer_duration;
-        bytes *= st->codecpar->ch_layout.nb_channels * st->codecpar->sample_rate *
-                 av_get_bytes_per_sample(st->codecpar->format);
-        bytes /= 1000;
+        int64_t bytes = av_rescale(s->buffer_duration,
+                                   st->codecpar->ch_layout.nb_channels *
+                                    (int64_t)st->codecpar->sample_rate *
+                                    av_get_bytes_per_sample(st->codecpar->format),
+                                   1000);
         buffer_attributes.tlength = FFMAX(s->buffer_size, av_clip64(bytes, 0, UINT32_MAX - 1));
         av_log(s, AV_LOG_DEBUG,
                "Buffer duration: %ums recalculated into %"PRId64" bytes buffer.\n",