From c889e1a4490a665a675d845488b11b30d86cea26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Fri, 20 Oct 2023 14:51:38 +0200 Subject: [PATCH] C++: Fix DataProducer::Send invalid memory access (#1190) 'subchannels' are optional and hence they need to be checked before accessing them. Remove test expectation that assumed we were receiving all messages in incremental mode. TS tests failure was being masked by [1], I don't know why Rust wasn't failing but definitely consumers are not receiving everything sent by the producer since in the tests both are paused at some time. [1]: https://github.com/versatica/mediasoup/issues/1188 --- node/src/tests/test-DirectTransport.ts | 2 +- rust/tests/integration/direct_transport.rs | 2 -- worker/src/RTC/DataProducer.cpp | 11 +++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/node/src/tests/test-DirectTransport.ts b/node/src/tests/test-DirectTransport.ts index 580185d96d..60034008fd 100644 --- a/node/src/tests/test-DirectTransport.ts +++ b/node/src/tests/test-DirectTransport.ts @@ -211,7 +211,7 @@ test('dataProducer.send() succeeds', async () => expect(ppid).toBe(53); // PPID of WebRTC DataChannel binary. } - expect(id).toBe(++lastRecvMessageId); + ++lastRecvMessageId; }); }); diff --git a/rust/tests/integration/direct_transport.rs b/rust/tests/integration/direct_transport.rs index ee80646f2a..290136f241 100644 --- a/rust/tests/integration/direct_transport.rs +++ b/rust/tests/integration/direct_transport.rs @@ -157,7 +157,6 @@ fn get_stats_succeeds() { } #[test] -#[ignore] fn send_succeeds() { future::block_on(async move { let (_worker, _router, transport) = init().await; @@ -226,7 +225,6 @@ fn send_succeeds() { } last_recv_message_id.fetch_add(1, Ordering::SeqCst); - assert_eq!(id, last_recv_message_id.load(Ordering::SeqCst)); if id == num_messages { let _ = received_messages_tx.lock().take().unwrap().send(()); diff --git a/worker/src/RTC/DataProducer.cpp b/worker/src/RTC/DataProducer.cpp index 56a3389e73..a55b58f6a9 100644 --- a/worker/src/RTC/DataProducer.cpp +++ b/worker/src/RTC/DataProducer.cpp @@ -224,11 +224,14 @@ namespace RTC std::vector subchannels; - subchannels.reserve(body->subchannels()->size()); - - for (const auto subchannel : *body->subchannels()) + if (flatbuffers::IsFieldPresent(body, FBS::DataProducer::SendNotification::VT_SUBCHANNELS)) { - subchannels.emplace_back(subchannel); + subchannels.reserve(body->subchannels()->size()); + + for (const auto subchannel : *body->subchannels()) + { + subchannels.emplace_back(subchannel); + } } std::optional requiredSubchannel{ std::nullopt };