Commit 5db57d9c authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix memory access problems in KisExifIo

The problems were caught by KisJpegTest. I have a feeling
there are more problems hidden (all of them are basically
incorrect pointer size iteration).
parent 1215b5c0
......@@ -143,6 +143,7 @@ KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::AutoPtr value,
const Exiv2::DataValue* dvalue = dynamic_cast<const Exiv2::DataValue*>(&*value);
Q_ASSERT(dvalue);
QByteArray array(dvalue->count(), 0);
dvalue->copy((Exiv2::byte*)array.data());
int columns = fixEndianess<quint16>((reinterpret_cast<quint16*>(array.data()))[0], order);
int rows = fixEndianess<quint16>((reinterpret_cast<quint16*>(array.data()))[1], order);
......@@ -168,13 +169,14 @@ KisMetaData::Value exifOECFToKMDOECFStructure(const Exiv2::Value::AutoPtr value,
names.append(KisMetaData::Value(""));
}
}
oecfStructure["Names"] = KisMetaData::Value(names, KisMetaData::Value::OrderedArray);
QList<KisMetaData::Value> values;
qint16* dataIt = reinterpret_cast<qint16*>(array.data() + index);
qint32* dataIt = reinterpret_cast<qint32*>(array.data() + index);
for (int i = 0; i < columns; i++) {
for (int j = 0; j < rows; j++) {
values.append(KisMetaData::Value(KisMetaData::Rational(fixEndianess<qint32>(dataIt[0], order), fixEndianess<qint32>(dataIt[1], order))));
dataIt += 8;
dataIt += 2;
}
}
oecfStructure["Values"] = KisMetaData::Value(values, KisMetaData::Value::OrderedArray);
......@@ -244,8 +246,10 @@ KisMetaData::Value deviceSettingDescriptionExifToKMD(const Exiv2::Value::AutoPtr
for (int index = 4; index < array.size(); )
{
int lastIndex = array.indexOf(null, index);
QString setting = QString::fromUtf16((ushort*)(void*)( array.data() + index), lastIndex - index + 2);
const int lastIndex = array.indexOf(null, index);
const int numChars = (lastIndex - index) / 2; // including trailing zero
QString setting = QString::fromUtf16((ushort*)(void*)( array.data() + index), numChars);
index = lastIndex + 2;
dbgMetaData << "Setting << " << setting;
settings.append(KisMetaData::Value(setting));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment