Bug 251044 - Fix clang-tidy bugprone-infinite-loop warnings in WebCore::AudioSampleDataSource::pullAvailableSamplesAsChunks()
Summary: Fix clang-tidy bugprone-infinite-loop warnings in WebCore::AudioSampleDataSou...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-01-23 15:02 PST by David Kilzer (:ddkilzer)
Modified: 2023-01-23 16:25 PST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2023-01-23 15:02:54 PST
Fix clang-tidy bugprone-infinite-loop warnings in WebCore::AudioSampleDataSource::pullAvailableSamplesAsChunks().

In `Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm`, the following `while()` loops can result in infinite loops if `sampleCountPerChunk` is zero (since there is no check that `sampleCountPerChunk` is non-zero):

```
bool AudioSampleDataSource::pullAvailableSamplesAsChunks(AudioBufferList& buffer, size_t sampleCountPerChunk, uint64_t timeStamp, Function<void()>&& consumeFilledBuffer)
{
    [...]
    if (m_muted) {
        AudioSampleBufferList::zeroABL(buffer, sampleCountPerChunk * m_outputDescription->bytesPerFrame());
        while (endFrame - startFrame >= sampleCountPerChunk) {
            consumeFilledBuffer();
            startFrame += sampleCountPerChunk;
        }
        return true;
    }

    while (endFrame - startFrame >= sampleCountPerChunk) {
        m_ringBuffer->fetch(&buffer, sampleCountPerChunk, startFrame, CARingBuffer::Copy);
        consumeFilledBuffer();
        startFrame += sampleCountPerChunk;
    }
    return true;
}
```
<https://github.com/WebKit/WebKit/blob/main/Source/WebCore/platform/audio/cocoa/AudioSampleDataSource.mm#L317>

Found by clang static analyzer.
Comment 1 Radar WebKit Bug Importer 2023-01-23 15:03:46 PST
<rdar://problem/104575403>
Comment 2 David Kilzer (:ddkilzer) 2023-01-23 16:25:30 PST
Pull request: https://github.com/WebKit/WebKit/pull/9001