Commit 5fbce88e authored by Volker Krause's avatar Volker Krause Committed by Albert Astals Cid

Fix memory issues in GfxImageColorMap copy ctor

- byte_lookup and lookup2 could contain uninitialized memory
- lookup2 was not copied at all
- lookup could be copied with the wrong size

Issue #145
parent 2b5f35e5
Pipeline #3459 passed with stage
in 2 minutes and 31 seconds
......@@ -31,6 +31,7 @@
// Copyright (C) 2016 Marek Kasik <mkasik@redhat.com>
// Copyright (C) 2017 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2018 Volker Krause <vkrause@kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -5868,24 +5869,30 @@ GfxImageColorMap::GfxImageColorMap(GfxImageColorMap *colorMap) {
colorSpace2 = nullptr;
for (k = 0; k < gfxColorMaxComps; ++k) {
lookup[k] = nullptr;
lookup2[k] = nullptr;
}
byte_lookup = nullptr;
n = 1 << bits;
for (k = 0; k < nComps; ++k) {
lookup[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup[k], colorMap->lookup[k], n * sizeof(GfxColorComp));
}
if (colorSpace->getMode() == csIndexed) {
colorSpace2 = ((GfxIndexedColorSpace *)colorSpace)->getBase();
for (k = 0; k < nComps2; ++k) {
lookup[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup[k], colorMap->lookup[k], n * sizeof(GfxColorComp));
lookup2[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup2[k], colorMap->lookup2[k], n * sizeof(GfxColorComp));
}
} else if (colorSpace->getMode() == csSeparation) {
colorSpace2 = ((GfxSeparationColorSpace *)colorSpace)->getAlt();
for (k = 0; k < nComps2; ++k) {
lookup[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup[k], colorMap->lookup[k], n * sizeof(GfxColorComp));
lookup2[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup2[k], colorMap->lookup2[k], n * sizeof(GfxColorComp));
}
} else {
for (k = 0; k < nComps; ++k) {
lookup[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup[k], colorMap->lookup[k], n * sizeof(GfxColorComp));
lookup2[k] = (GfxColorComp *)gmallocn(n, sizeof(GfxColorComp));
memcpy(lookup2[k], colorMap->lookup2[k], n * sizeof(GfxColorComp));
}
}
if (colorMap->byte_lookup) {
......
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