CodeQL fixes, take 2 (#745)

* Protect values against integer overflow

When the code multiplies integer values in an rvalue context before
it's stored in a larger type, the on-the-fly math is stored as int.
The value can overflow before it reaches the wider memory space.

To prevent this, we explicitly cast the result of the arithmetic
to the destination type.

Issues flagged by GitHub CodeQL.

* Apply these fixes correctly
This commit is contained in:
Frank Dana
2021-10-03 07:01:56 -04:00
committed by GitHub
parent ac956f05f1
commit d78ac099d6
3 changed files with 15 additions and 18 deletions

View File

@@ -1537,10 +1537,9 @@ void FFmpegReader::ProcessAudioPacket(int64_t requested_frame, int64_t target_fr
// Copy audio samples over original samples
memcpy(audio_buf,
audio_converted->data[0],
static_cast<size_t>(
audio_converted->nb_samples
static_cast<size_t>(audio_converted->nb_samples)
* av_get_bytes_per_sample(AV_SAMPLE_FMT_S16)
* info.channels)
* info.channels
);
// Deallocate resample buffer