Title: [294334] trunk/Source/WebCore/platform/mediastream/mac/MockAudioSharedUnit.mm
Revision
294334
Author
[email protected]
Date
2022-05-17 12:46:29 -0700 (Tue, 17 May 2022)

Log Message

MockAudioSharedInternalUnit::render should return kAudio_ParamError if input buffer is too small
https://bugs.webkit.org/show_bug.cgi?id=240518
rdar://93409662

Patch by Youenn Fablet <[email protected]> on 2022-05-17
Reviewed by Eric Carlson.

The input buffer given to render should be large enough to copy enough frameCount samples.
If that is not the case, mimick what the real audio unit is doing and return kAudio_ParamError.
We also more closely mimick the real audio unit by sending chunks of at most AudioSession::sharedSession().bufferSize().

Covered by existing tests.

* Source/WebCore/platform/mediastream/mac/MockAudioSharedUnit.mm:
(WebCore::MockAudioSharedInternalUnit::generateSampleBuffers):
(WebCore::MockAudioSharedInternalUnit::render):

Canonical link: https://commits.webkit.org/250654@main

Modified Paths

Diff

Modified: trunk/Source/WebCore/platform/mediastream/mac/MockAudioSharedUnit.mm (294333 => 294334)


--- trunk/Source/WebCore/platform/mediastream/mac/MockAudioSharedUnit.mm	2022-05-17 19:39:36 UTC (rev 294333)
+++ trunk/Source/WebCore/platform/mediastream/mac/MockAudioSharedUnit.mm	2022-05-17 19:46:29 UTC (rev 294334)
@@ -320,7 +320,7 @@
         reconfigure();
 
     uint32_t totalFrameCount = alignTo16Bytes(delta.seconds() * sampleRate());
-    uint32_t frameCount = std::min(totalFrameCount, m_maximiumFrameCount);
+    uint32_t frameCount = std::min(totalFrameCount, static_cast<uint32_t>(AudioSession::sharedSession().bufferSize()));
 
     while (frameCount) {
         uint32_t bipBopStart = m_samplesRendered % m_bipBopBuffer.size();
@@ -334,7 +334,7 @@
         emitSampleBuffers(bipBopCount);
         m_samplesRendered += bipBopCount;
         totalFrameCount -= bipBopCount;
-        frameCount = std::min(totalFrameCount, m_maximiumFrameCount);
+        frameCount = std::min(totalFrameCount, static_cast<uint32_t>(AudioSession::sharedSession().bufferSize()));
     }
 }
 
@@ -344,10 +344,15 @@
     if (buffer->mNumberBuffers > sourceBuffer->mNumberBuffers)
         return kAudio_ParamError;
 
+    auto copySize = frameCount * m_streamFormat.mBytesPerPacket;
     for (uint32_t i = 0; i < buffer->mNumberBuffers; i++) {
+        ASSERT(copySize <= sourceBuffer->mBuffers[i].mDataByteSize);
+        if (copySize > buffer->mBuffers[i].mDataByteSize)
+            return kAudio_ParamError;
+
         auto* source = static_cast<uint8_t*>(sourceBuffer->mBuffers[i].mData);
         auto* destination = static_cast<uint8_t*>(buffer->mBuffers[i].mData);
-        memcpy(destination, source, frameCount * m_streamFormat.mBytesPerPacket);
+        memcpy(destination, source, copySize);
     }
 
     return 0;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to