From 7624d03d1466d22708adb6ff50a0eb7a5b379179 Mon Sep 17 00:00:00 2001 From: Hiroki KUMAZAKI Date: Sun, 27 Sep 2026 18:47:32 +0900 Subject: [PATCH] android: reject a zero sample rate or channel count in oto_oboe_Play OpenLocked divides the requested buffer size by channel_num_ and PrepareBuffersLocked converts the buffer to microseconds by dividing by sample_rate_, so a zero from the caller faults the process instead of failing the way every other bad configuration does. oto does not check the two options when the default buffer size is used, and the extern entry point is callable on its own. --- internal/oboe/binding_android.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/oboe/binding_android.cpp b/internal/oboe/binding_android.cpp index 05bc529..574ebd9 100644 --- a/internal/oboe/binding_android.cpp +++ b/internal/oboe/binding_android.cpp @@ -354,6 +354,15 @@ void Stream::DeferStartLocked() { const char *Stream::Play(int sample_rate, int channel_num, int buffer_size_in_bytes) { + // The frame counts and the read wait below divide by these, so a value the + // caller left at zero would fault instead of reporting a bad configuration. + if (sample_rate <= 0) { + return "oto_oboe_Play: sample rate must be positive"; + } + if (channel_num <= 0) { + return "oto_oboe_Play: channel count must be positive"; + } + std::lock_guard lock{mutex_}; sample_rate_ = sample_rate; channel_num_ = channel_num;