summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2021-03-29 19:12:23 +0200
committerAlbert Astals Cid <aacid@kde.org>2021-03-29 19:12:23 +0200
commit104fc940ca3c3eb8b706abd11d35be83dbcd0c3b (patch)
treeb184cbb564d711b07fcc712cd3167988ace209c6
parent29c3fc62d4997bb514d4748cca264fc6868cb52d (diff)
pdfimages: Do not assert in "too big images"
Fixes #1061
-rw-r--r--utils/ImageOutputDev.cc16
1 files changed, 10 insertions, 6 deletions
diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc
index 879d94ee..4bb9d8ab 100644
--- a/utils/ImageOutputDev.cc
+++ b/utils/ImageOutputDev.cc
@@ -373,6 +373,16 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
}
}
+ int pixelSize = sizeof(unsigned int);
+ if (format == imgRGB48)
+ pixelSize = 2 * sizeof(unsigned int);
+
+ row = (unsigned char *)gmallocn_checkoverflow(width, pixelSize);
+ if (!row) {
+ error(errIO, -1, "Image data for '{0:s}' is too big. {1:d} width with {2:d} bytes per pixel", fileName, width, pixelSize);
+ return;
+ }
+
if (format != imgMonochrome) {
// initialize stream
imgStr = new ImageStream(str, width, colorMap->getNumPixelComps(), colorMap->getBits());
@@ -382,12 +392,6 @@ void ImageOutputDev::writeImageFile(ImgWriter *writer, ImageFormat format, const
str->reset();
}
- int pixelSize = sizeof(unsigned int);
- if (format == imgRGB48)
- pixelSize = 2 * sizeof(unsigned int);
-
- row = (unsigned char *)gmallocn(width, pixelSize);
-
// PDF masks use 0 = draw current color, 1 = leave unchanged.
// We invert this to provide the standard interpretation of alpha
// (0 = transparent, 1 = opaque). If the colorMap already inverts