Check the input buffer before passing it to libheif

This commit is contained in:
Daniel Novomesky
2021-03-02 12:35:27 +01:00
committed by Daniel Novomeský
parent c532227d43
commit 511a22f0b4
2 changed files with 8 additions and 1 deletions

View File

@ -261,6 +261,11 @@ bool HEIFHandler::canRead(QIODevice *device)
} }
const QByteArray header = device->peek(28); const QByteArray header = device->peek(28);
return HEIFHandler::isSupportedBMFFType(header);
}
bool HEIFHandler::isSupportedBMFFType(const QByteArray &header)
{
if (header.size() < 28) { if (header.size() < 28) {
return false; return false;
} }
@ -364,7 +369,7 @@ bool HEIFHandler::ensureDecoder()
} }
const QByteArray buffer = device()->readAll(); const QByteArray buffer = device()->readAll();
if (buffer.isEmpty()) { if (!HEIFHandler::isSupportedBMFFType(buffer)) {
m_parseState = ParseHeicError; m_parseState = ParseHeicError;
return false; return false;
} }

View File

@ -10,6 +10,7 @@
#ifndef KIMG_HEIF_P_H #ifndef KIMG_HEIF_P_H
#define KIMG_HEIF_P_H #define KIMG_HEIF_P_H
#include <QByteArray>
#include <QImage> #include <QImage>
#include <QImageIOPlugin> #include <QImageIOPlugin>
@ -28,6 +29,7 @@ public:
void setOption(ImageOption option, const QVariant &value) override; void setOption(ImageOption option, const QVariant &value) override;
bool supportsOption(ImageOption option) const override; bool supportsOption(ImageOption option) const override;
private: private:
static bool isSupportedBMFFType(const QByteArray &header);
bool ensureParsed() const; bool ensureParsed() const;
bool ensureDecoder(); bool ensureDecoder();