From 8f97d76080b9617fc67d01f2bc8de36a5b0a1175 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 6 May 2019 19:28:35 +0000 Subject: archive: fixed crash on some corrupted archives (#998) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8861 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/archive/archiveinputdevice.cpp | 14 +++++++++++++- src/plugins/Input/archive/decoderarchivefactory.cpp | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/plugins/Input/archive/archiveinputdevice.cpp b/src/plugins/Input/archive/archiveinputdevice.cpp index 22cfa2372..5b11a2938 100644 --- a/src/plugins/Input/archive/archiveinputdevice.cpp +++ b/src/plugins/Input/archive/archiveinputdevice.cpp @@ -80,6 +80,9 @@ ArchiveInputDevice::~ArchiveInputDevice() bool ArchiveInputDevice::seek(qint64 pos) { + if(!isOpen()) + return false; + QIODevice::seek(pos); if(pos > m_buffer.size()) @@ -99,10 +102,11 @@ bool ArchiveInputDevice::seek(qint64 pos) else if(r < 0) { qWarning("ArchiveInputDevice: seeking failed; libarchive error: %s", archive_error_string(m_archive)); + setErrorString(QString::fromLocal8Bit(archive_error_string(m_archive))); + close(); } return false; } - } return m_buffer.seek(pos); @@ -115,6 +119,9 @@ qint64 ArchiveInputDevice::size() const qint64 ArchiveInputDevice::readData(char *data, qint64 maxSize) { + if(!isOpen()) + return -1; + if(m_buffer.pos() + maxSize > m_buffer.size()) { qint64 l = m_buffer.pos() + maxSize - m_buffer.size(); @@ -123,7 +130,12 @@ qint64 ArchiveInputDevice::readData(char *data, qint64 maxSize) if(r > 0) m_buffer.buffer().append(tmp, r); else if(r < 0) + { qWarning("ArchiveInputDevice: reading failed; libarchive error: %s", archive_error_string(m_archive)); + setErrorString(QString::fromLocal8Bit(archive_error_string(m_archive))); + close(); + return -1; + } } return m_buffer.read(data, maxSize); } diff --git a/src/plugins/Input/archive/decoderarchivefactory.cpp b/src/plugins/Input/archive/decoderarchivefactory.cpp index 3b83616c2..119e30d83 100644 --- a/src/plugins/Input/archive/decoderarchivefactory.cpp +++ b/src/plugins/Input/archive/decoderarchivefactory.cpp @@ -112,6 +112,14 @@ QList DecoderArchiveFactory::createPlayList(const QString &path, Tr ArchiveInputDevice dev(a, entry, nullptr); ArchiveTagReader reader(&dev, list.last()->path()); + if(!dev.isOpen()) + { + qDeleteAll(list); + list.clear(); + archive_read_free(a); + return list; + } + if(parts & TrackInfo::MetaData) list.last()->setValues(reader.metaData()); -- cgit v1.2.3-13-gbd6f