[SVACE] Possible integer overflow in expression 72/315972/3
authorAdam Bujalski <a.bujalski@samsung.com>
Fri, 6 Dec 2024 08:17:20 +0000 (09:17 +0100)
committerBot Blink <blinkbot@samsung.com>
Mon, 9 Dec 2024 09:08:06 +0000 (09:08 +0000)
[Problem]
SVACE Warning Message:
The value of an arithmetic expression 'bytes_per_frame_ * sample_rate_'
is a subject to overflow because its operands are not cast to a larger
data type before performing arithmetic

[Solution]
Due to restriction on maximal values of:
- `bytes_per_frame_` - it is maximum number of bytes per audio frame
  and can be at most 8 * 4 = 32, as there will at most 8 audio channels
  and each channel date will be at most 4 bytes per (in case of using
  32bit float value).
- `sample_rate_` - it is maximum audio sampling rate most probably 48kHz
  with maximal values just below 200kHz.
So value of mentioned expression won't be larger than 6'400'000
(32 * 200'000), which fits 32bit unsigned integer.

To explicitly express this separate variable holding value of this
expression is added.

Bug: DF241205-01887
Bug: https://jira-eu.sec.samsung.net/browse/VDWASM-2009
Signed-off-by: Adam Bujalski <a.bujalski@samsung.com>
Change-Id: I474dd075f9296027b24b08a4199fe25b5403cda2

tizen_src/chromium_impl/media/audio/tizen/mch_pcm_output.cc

index a7d796c3db543be79f13c52123915d38b788e823..57b2a84be9571afe2a282d1e54f594c72a49b2dd 100644 (file)
@@ -209,9 +209,10 @@ base::TimeDelta MchPcmOutputStream::WritePacket() {
 
   // Write at most kDefaultChunkDuration of audio data to ensure
   // that device will be filled constantly.
-  const int max_write_size = (bytes_per_frame_ * sample_rate_ *
-                              kDefaultChunkDuration.InMilliseconds()) /
-                             base::Time::kMillisecondsPerSecond;
+  const uint32_t bytes_per_second = bytes_per_frame_ * sample_rate_;
+  const int max_write_size =
+      (bytes_per_second * kDefaultChunkDuration.InMilliseconds()) /
+      base::Time::kMillisecondsPerSecond;
   const int write_size = std::min(buffer_size, max_write_size);
   size_t bytes_written = device_->Write(buffer_data, write_size);
   if (bytes_written > 0) {