From 2c5ae5d4908d79a44f77e0a4fe9672c172155b3c Mon Sep 17 00:00:00 2001 From: h3ndrik Date: Sat, 13 Apr 2019 01:21:00 +0200 Subject: [PATCH] don't try to read 0 bytes if we hit the icy block (fixes #124) (#125) * don't try to read 0 bytes if we hit the icy block * make sure size isn't negative --- src/AudioFileSourceICYStream.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/AudioFileSourceICYStream.cpp b/src/AudioFileSourceICYStream.cpp index fdf70f2..551619a 100644 --- a/src/AudioFileSourceICYStream.cpp +++ b/src/AudioFileSourceICYStream.cpp @@ -164,13 +164,17 @@ retry: // If the read would hit an ICY block, split it up... if (((int)(icyByteCount + len) > (int)icyMetaInt) && (icyMetaInt > 0)) { int beforeIcy = icyMetaInt - icyByteCount; - int ret = stream->read(reinterpret_cast(data), beforeIcy); - read += ret; - pos += ret; - len -= ret; - data = (void *)(reinterpret_cast(data) + ret); - icyByteCount += ret; - if (ret != beforeIcy) return read; // Partial read + int ret = 0; + if (beforeIcy > 0) { + ret = stream->read(reinterpret_cast(data), beforeIcy); + if (ret < 0) ret = 0; + read += ret; + pos += ret; + len -= ret; + data = (void *)(reinterpret_cast(data) + ret); + icyByteCount += ret; + if (ret != beforeIcy) return read; // Partial read + } uint8_t mdSize; int mdret = stream->read(&mdSize, 1); @@ -225,6 +229,7 @@ retry: } int ret = stream->read(reinterpret_cast(data), len); + if (ret < 0) ret = 0; read += ret; pos += ret; icyByteCount += ret;