Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loop when decoding corrupt MP3 files #2417

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
==== 2.2.4 2020-mm-dd ====
* Prevent infinite loop when decoding corrupt MP3 files #2417

==== 2.2.3 2019-11-24 ====
* Don't make users reconfigure sound hardware when it has not changed #2253
* Fix MusicBrainz metadata lookup lp:1848887 #2328
Expand Down
21 changes: 17 additions & 4 deletions src/sources/soundsourcemp3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ ReadableSampleFrames SoundSourceMp3::readSampleFramesClamped(

CSAMPLE* pSampleBuffer = writableSampleFrames.writableData();
SINT numberOfFramesRemaining = numberOfFramesTotal;
SINT retryFrameIndex = numberOfFramesTotal;
while (0 < numberOfFramesRemaining) {
bool abortReading = false;

Expand Down Expand Up @@ -645,11 +646,23 @@ ReadableSampleFrames SoundSourceMp3::readSampleFramesClamped(
}
}
if (pMadThisFrame == m_madStream.this_frame) {
if (kLogger.debugEnabled()) {
kLogger.debug() << "Retry decoding MP3 frame @" << m_curFrameIndex;
// Retry decoding, but only once for each position to
// prevent infinite loops when decoding corrupt files
if (retryFrameIndex != m_curFrameIndex) {
retryFrameIndex = m_curFrameIndex;
if (kLogger.debugEnabled()) {
kLogger.debug()
<< "Retry decoding MP3 frame @"
<< m_curFrameIndex;
}
continue;
} else {
kLogger.warning()
<< "Decoding MP3 frame @"
<< m_curFrameIndex
<< "failed again";
break;
}
// Retry decoding
continue;
}

DEBUG_ASSERT(isStreamValid(m_madStream));
Expand Down