71 lines
2.6 KiB
Diff
71 lines
2.6 KiB
Diff
|
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp
|
||
|
index 7ba44049..8c4be4f0 100644
|
||
|
--- a/src/gui/image/qxbmhandler.cpp
|
||
|
+++ b/src/gui/image/qxbmhandler.cpp
|
||
|
@@ -158,7 +158,9 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage)
|
||
|
w = (w+7)/8; // byte width
|
||
|
|
||
|
while (y < h) { // for all encoded bytes...
|
||
|
- if (p) { // p = "0x.."
|
||
|
+ if (p && p < (buf + readBytes - 3)) { // p = "0x.."
|
||
|
+ if (!isxdigit(p[2]) || !isxdigit(p[3]))
|
||
|
+ return false;
|
||
|
*b++ = hex2byte(p+2);
|
||
|
p += 2;
|
||
|
if (++x == w && ++y < h) {
|
||
|
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
|
||
|
index 1eee2f27..f801f3cd 100644
|
||
|
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
|
||
|
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
|
||
|
@@ -167,6 +167,8 @@ private slots:
|
||
|
void devicePixelRatio_data();
|
||
|
void devicePixelRatio();
|
||
|
|
||
|
+ void xbmBufferHandling();
|
||
|
+
|
||
|
private:
|
||
|
QString prefix;
|
||
|
QTemporaryDir m_temporaryDir;
|
||
|
@@ -2002,5 +2004,41 @@ void tst_QImageReader::devicePixelRatio()
|
||
|
QCOMPARE(img.devicePixelRatio(), dpr);
|
||
|
}
|
||
|
|
||
|
+void tst_QImageReader::xbmBufferHandling()
|
||
|
+{
|
||
|
+ uint8_t original_buffer[256];
|
||
|
+ for (int i = 0; i < 256; ++i)
|
||
|
+ original_buffer[i] = i;
|
||
|
+
|
||
|
+ QImage image(original_buffer, 256, 8, QImage::Format_MonoLSB);
|
||
|
+ image.setColorTable({0xff000000, 0xffffffff});
|
||
|
+
|
||
|
+ QByteArray buffer;
|
||
|
+ {
|
||
|
+ QBuffer buf(&buffer);
|
||
|
+ QImageWriter writer(&buf, "xbm");
|
||
|
+ writer.write(image);
|
||
|
+ }
|
||
|
+
|
||
|
+ QCOMPARE(QImage::fromData(buffer, "xbm"), image);
|
||
|
+
|
||
|
+ auto i = buffer.indexOf(',');
|
||
|
+ buffer.insert(i + 1, " ");
|
||
|
+ QCOMPARE(QImage::fromData(buffer, "xbm"), image);
|
||
|
+ buffer.insert(i + 1, " ");
|
||
|
+ QCOMPARE(QImage::fromData(buffer, "xbm"), image);
|
||
|
+ buffer.insert(i + 1, " ");
|
||
|
+#if 0 // Lines longer than 300 chars not supported currently
|
||
|
+ QCOMPARE(QImage::fromData(buffer, "xbm"), image);
|
||
|
+#endif
|
||
|
+
|
||
|
+ i = buffer.lastIndexOf("\n ");
|
||
|
+ buffer.truncate(i + 1);
|
||
|
+ buffer.append(QByteArray(297, ' '));
|
||
|
+ buffer.append("0x");
|
||
|
+ // Only check we get no buffer overflow
|
||
|
+ QImage::fromData(buffer, "xbm");
|
||
|
+}
|
||
|
+
|
||
|
QTEST_MAIN(tst_QImageReader)
|
||
|
#include "tst_qimagereader.moc"
|