This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 779ab041468d6be92ce14bdb65a3deb0eef4707e
Author: Krzysztof Kopyściński <[email protected]>
AuthorDate: Fri May 10 08:20:03 2024 +0200

    apps/auracast_usb: fix crash on to much/corrupted data on USB
    
    If USB pushes more data then it should, handle it more gracefully.
---
 apps/auracast_usb/src/audio_usb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/apps/auracast_usb/src/audio_usb.c 
b/apps/auracast_usb/src/audio_usb.c
index d0c5fee4..3d51be51 100644
--- a/apps/auracast_usb/src/audio_usb.c
+++ b/apps/auracast_usb/src/audio_usb.c
@@ -154,7 +154,11 @@ usb_data_func(struct os_event *ev)
     }
 
     while ((num_bytes = tud_audio_available()) > 0) {
-        num_samples = num_bytes / AUDIO_SAMPLE_SIZE;
+        num_frames = num_bytes / (AUDIO_CHANNELS * AUDIO_SAMPLE_SIZE);
+        num_samples = num_frames * AUDIO_CHANNELS;
+        if (out_idx + num_samples >= ARRAY_SIZE(out_buf)) {
+            num_samples = ARRAY_SIZE(out_buf) - out_idx - 1;
+        }
         num_frames = num_samples / AUDIO_CHANNELS;
         num_bytes = num_frames * AUDIO_SAMPLE_SIZE * AUDIO_CHANNELS;
 

Reply via email to