Skip to content

Commit 0d415c0

Browse files
Fixed possible buffer overread (#119)
1 parent 98c2dfa commit 0d415c0

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/ESP32_VS1053_Stream.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,11 @@ void ESP32_VS1053_Stream::_playFromRingBuffer()
420420

421421
[[maybe_unused]] const auto startTimeMS = millis();
422422
size_t bytesToDecoder = 0;
423-
while (_remainingBytes && bytesToDecoder < VS1053_PSRAM_MAX_MOVE && _vs1053->data_request())
423+
while (_remainingBytes && _vs1053->data_request())
424424
{
425425
size_t size = 0;
426-
uint8_t *data = (uint8_t *)xRingbufferReceiveUpTo(_ringbuffer_handle, &size, pdMS_TO_TICKS(0), VS1053_PLAYBUFFER_SIZE);
426+
size_t avail = min(VS1053_PLAYBUFFER_SIZE, (size_t)_remainingBytes);
427+
uint8_t *data = (uint8_t *)xRingbufferReceiveUpTo(_ringbuffer_handle, &size, pdMS_TO_TICKS(0), avail);
427428
if (!data)
428429
{
429430
if (!_bufferStallStartMS)

0 commit comments

Comments
 (0)