From 964624ba400d2dc82b7b6de027951282496c6089 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Sun, 27 Jan 2019 12:50:19 +0100 Subject: [PATCH] xcf: Don't cast int to enum that can't hold that int value --- src/imageformats/gimp_p.h | 3 ++- src/imageformats/xcf.cpp | 30 +++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/imageformats/gimp_p.h b/src/imageformats/gimp_p.h index 028653b..32d5b47 100644 --- a/src/imageformats/gimp_p.h +++ b/src/imageformats/gimp_p.h @@ -125,7 +125,8 @@ typedef enum { PROP_PARASITES = 21, PROP_UNIT = 22, PROP_PATHS = 23, - PROP_USER_UNIT = 24 + PROP_USER_UNIT = 24, + MAX_SUPPORTED_PROPTYPE // should always be at the end so its value is last + 1 } PropType; // From GIMP "xcf.c" v1.2 diff --git a/src/imageformats/xcf.cpp b/src/imageformats/xcf.cpp index b0c6028..25f195c 100644 --- a/src/imageformats/xcf.cpp +++ b/src/imageformats/xcf.cpp @@ -181,7 +181,7 @@ private: static const LayerModes layer_modes[]; bool loadImageProperties(QDataStream &xcf_io, XCFImage &image); - bool loadProperty(QDataStream &xcf_io, PropType &type, QByteArray &bytes); + bool loadProperty(QDataStream &xcf_io, PropType &type, QByteArray &bytes, quint32 &rawType); bool loadLayer(QDataStream &xcf_io, XCFImage &xcf_image); bool loadLayerProperties(QDataStream &xcf_io, Layer &layer); bool composeTiles(XCFImage &xcf_image); @@ -387,8 +387,9 @@ bool XCFImageFormat::loadImageProperties(QDataStream &xcf_io, XCFImage &xcf_imag while (true) { PropType type; QByteArray bytes; + quint32 rawType; - if (!loadProperty(xcf_io, type, bytes)) { + if (!loadProperty(xcf_io, type, bytes, rawType)) { // qDebug() << "XCF: error loading global image properties"; return false; } @@ -457,7 +458,7 @@ bool XCFImageFormat::loadImageProperties(QDataStream &xcf_io, XCFImage &xcf_imag break; default: -// qDebug() << "XCF: unimplemented image property" << type +// qDebug() << "XCF: unimplemented image property" << rawType // << ", size " << bytes.size() << endl; break; } @@ -471,11 +472,16 @@ bool XCFImageFormat::loadImageProperties(QDataStream &xcf_io, XCFImage &xcf_imag * \param type returns with the property type. * \param bytes returns with the property data. * \return true if there were no IO errors. */ -bool XCFImageFormat::loadProperty(QDataStream &xcf_io, PropType &type, QByteArray &bytes) +bool XCFImageFormat::loadProperty(QDataStream &xcf_io, PropType &type, QByteArray &bytes, quint32 &rawType) { - quint32 foo; - xcf_io >> foo; - type = PropType(foo); // TODO urks + xcf_io >> rawType; + if (rawType >= MAX_SUPPORTED_PROPTYPE) { + type = MAX_SUPPORTED_PROPTYPE; + // return true because we don't really want to totally fail on an unsupported property since it may not be fatal + return true; + } + + type = PropType(rawType); char *data = nullptr; quint32 size; @@ -634,8 +640,9 @@ bool XCFImageFormat::loadLayerProperties(QDataStream &xcf_io, Layer &layer) while (true) { PropType type; QByteArray bytes; + quint32 rawType; - if (!loadProperty(xcf_io, type, bytes)) { + if (!loadProperty(xcf_io, type, bytes, rawType)) { // qDebug() << "XCF: error loading layer properties"; return false; } @@ -691,7 +698,7 @@ bool XCFImageFormat::loadLayerProperties(QDataStream &xcf_io, Layer &layer) break; default: -// qDebug() << "XCF: unimplemented layer property " << type +// qDebug() << "XCF: unimplemented layer property " << rawType // << ", size " << bytes.size() << endl; break; } @@ -1218,8 +1225,9 @@ bool XCFImageFormat::loadChannelProperties(QDataStream &xcf_io, Layer &layer) while (true) { PropType type; QByteArray bytes; + quint32 rawType; - if (!loadProperty(xcf_io, type, bytes)) { + if (!loadProperty(xcf_io, type, bytes, rawType)) { // qDebug() << "XCF: error loading channel properties"; return false; } @@ -1252,7 +1260,7 @@ bool XCFImageFormat::loadChannelProperties(QDataStream &xcf_io, Layer &layer) break; default: -// qDebug() << "XCF: unimplemented channel property " << type +// qDebug() << "XCF: unimplemented channel property " << rawType // << ", size " << bytes.size() << endl; break; }