cras_input: Fix for a potential security issue
1. Add DCHECK to make sure audio_bus_->frames() is equal to CRAS actually delivered.
2. Added span for audio cras buffer.
diff --git a/media/audio/cras/cras_input.cc b/media/audio/cras/cras_input.cc
index edb8f56..9a22b11 100644
--- a/media/audio/cras/cras_input.cc
+++ b/media/audio/cras/cras_input.cc
@@ -502,9 +502,13 @@
// The delay says how long ago the capture was, so we subtract the delay from
// Now() to find the capture time.
const base::TimeTicks capture_time = base::TimeTicks::Now() - delay;
-
- audio_bus_->FromInterleaved<SignedInt16SampleTypeTraits>(
- reinterpret_cast<int16_t*>(buffer), audio_bus_->frames());
+ // The frames should be equal to CRAS actually delivered.
+ DCHECK_EQ(static_cast<size_t>(audio_bus_->frames()), frames);
+ // SAFETY: buffer is guaranteed to be at least as large as the number of
+ // frames to read.
+ audio_bus_->FromInterleaved<SignedInt16SampleTypeTraits>(base::span(
+ reinterpret_cast<int16_t*>(buffer),
+ static_cast<size_t>(audio_bus_->channels() * audio_bus_->frames())));
peak_detector_.FindPeak(audio_bus_.get());
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi all, I have modified CL:7756967 and made sure this CL work. PTAL
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
audio_bus_->FromInterleaved<SignedInt16SampleTypeTraits>(base::span(need UNSAFE_BUFFERS?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
libcras_stream_cb_data_get_frames(data, &frames);
libcras_stream_cb_data_get_buf(data, &buf);
libcras_stream_cb_data_get_latency(data, &latency);
libcras_stream_cb_data_get_usr_arg(data, &usr_arg);
CrasInputStream* me = static_cast<CrasInputStream*>(usr_arg);
me->ReadAudio(frames, buf, &latency);drive-by: Would it be possible to convert (buf, frames) to a span<int16_t> as close as possible of the C library? Then we understand why we can't spanify further.
Then the "SAFETY:/UNSAFE_BUFFERS" comment would be easier to double check.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
libcras_stream_cb_data_get_frames(data, &frames);
libcras_stream_cb_data_get_buf(data, &buf);
libcras_stream_cb_data_get_latency(data, &latency);
libcras_stream_cb_data_get_usr_arg(data, &usr_arg);
CrasInputStream* me = static_cast<CrasInputStream*>(usr_arg);
me->ReadAudio(frames, buf, &latency);drive-by: Would it be possible to convert (buf, frames) to a span<int16_t> as close as possible of the C library? Then we understand why we can't spanify further.
Then the "SAFETY:/UNSAFE_BUFFERS" comment would be easier to double check.
I'm not sure how to do that. Do you have any example?
audio_bus_->FromInterleaved<SignedInt16SampleTypeTraits>(base::span(Yu-Hsuan Hsuneed UNSAFE_BUFFERS?
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
libcras_stream_cb_data_get_frames(data, &frames);
libcras_stream_cb_data_get_buf(data, &buf);
libcras_stream_cb_data_get_latency(data, &latency);
libcras_stream_cb_data_get_usr_arg(data, &usr_arg);
CrasInputStream* me = static_cast<CrasInputStream*>(usr_arg);
me->ReadAudio(frames, buf, &latency);Yu-Hsuan Hsudrive-by: Would it be possible to convert (buf, frames) to a span<int16_t> as close as possible of the C library? Then we understand why we can't spanify further.
Then the "SAFETY:/UNSAFE_BUFFERS" comment would be easier to double check.
I'm not sure how to do that. Do you have any example?
Update `CrasInputStream::ReadAudio` signature to use a span.
Create the span here instead of in L508
DCHECK_EQ(static_cast<size_t>(audio_bus_->frames()), frames);Can this be a CHECK ? Otherwise, we still have a potential OOB, because users don't run with CHECK enabled in general.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |