Skip to content

Commit 217778b

Browse files
More checks to make sure we dont run out of data.
Hopefully usefull comment about the stream ptr.
1 parent 38b3249 commit 217778b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ESP32_VS1053_Stream.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ void ESP32_VS1053_Stream::_handleChunkedStream(WiFiClient *const stream)
579579

580580
if (stream && stream->available() && _metaDataStart && _musicDataPosition == _metaDataStart && _bytesLeftInChunk)
581581
{
582-
const auto DATA_NEEDED = stream->peek() * 16 + 1;
582+
const auto DATA_NEEDED = stream->peek() * 16 + 20; /* plus 20 because there could be a end-of-chunk in the data */
583583
if (stream->available() < DATA_NEEDED)
584584
return;
585585

@@ -617,7 +617,10 @@ void ESP32_VS1053_Stream::_handleChunkedStream(WiFiClient *const stream)
617617
_musicDataPosition = 0;
618618
}
619619

620-
if (!_bytesLeftInChunk && !_checkSync(stream))
620+
if (stream && !_bytesLeftInChunk && stream->available() < 20) /* make sure we dont run out of data in the next test*/
621+
return;
622+
623+
if (stream && !_bytesLeftInChunk && !_checkSync(stream))
621624
{
622625
_remainingBytes = 0;
623626
return;
@@ -636,7 +639,7 @@ void ESP32_VS1053_Stream::loop()
636639
return;
637640
}
638641

639-
WiFiClient *const stream = _http->getStreamPtr();
642+
WiFiClient *const stream = _http->getStreamPtr(); /* this can be a NULL ptr at the end of real files when al stream data is read but not yet in the decoder */
640643
if (!_ringbuffer_handle && !stream)
641644
{
642645
log_e("Stream connection lost");

0 commit comments

Comments
 (0)