summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qppmhandler.cpp
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@theqtcompany.com>2015-11-16 09:57:12 +0100
committeraavit <eirik.aavitsland@theqtcompany.com>2015-11-19 08:06:07 +0000
commit711f7992988ab485347ebfd6b443005c0acf61d3 (patch)
treeb6996bb95ef588f3ccf20260b91b146bea7b1bfc /src/gui/image/qppmhandler.cpp
parent912df566d0ea99786cb31bc8fabea420d25a572f (diff)
Make the ppm image handler corrctly handle long comment lines
The ppm decoder used a fixed size buffer to discard comment lines, which would fail for comments longer than 100 characters. Task-number: QTBUG-49414 Change-Id: I92e910e025cf7584a6ff1c0e5b0e8a4ab281d479 Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'src/gui/image/qppmhandler.cpp')
-rw-r--r--src/gui/image/qppmhandler.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/gui/image/qppmhandler.cpp b/src/gui/image/qppmhandler.cpp
index f460431c2b..7f23656c02 100644
--- a/src/gui/image/qppmhandler.cpp
+++ b/src/gui/image/qppmhandler.cpp
@@ -46,13 +46,21 @@ QT_BEGIN_NAMESPACE
PBM/PGM/PPM (ASCII and RAW) image read/write functions
*****************************************************************************/
+static void discard_pbm_line(QIODevice *d)
+{
+ const int buflen = 100;
+ char buf[buflen];
+ int res = 0;
+ do {
+ res = d->readLine(buf, buflen);
+ } while (res > 0 && buf[res-1] != '\n');
+}
+
static int read_pbm_int(QIODevice *d)
{
char c;
int val = -1;
bool digit;
- const int buflen = 100;
- char buf[buflen];
for (;;) {
if (!d->getChar(&c)) // end of file
break;
@@ -63,7 +71,7 @@ static int read_pbm_int(QIODevice *d)
continue;
} else {
if (c == '#') // comment
- d->readLine(buf, buflen);
+ discard_pbm_line(d);
break;
}
}
@@ -72,7 +80,7 @@ static int read_pbm_int(QIODevice *d)
else if (isspace((uchar) c))
continue;
else if (c == '#')
- (void)d->readLine(buf, buflen);
+ discard_pbm_line(d);
else
break;
}