From 711f7992988ab485347ebfd6b443005c0acf61d3 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 16 Nov 2015 09:57:12 +0100 Subject: 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 --- src/gui/image/qppmhandler.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/gui/image/qppmhandler.cpp') 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; } -- cgit v1.2.3