From 4d044d5947bd7b49b93146097d934ccdce3746c2 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 7 Sep 2009 11:16:39 +0200 Subject: Fixed resolving colors of the form "rgb(r,g,b)" in SVGs. The bug was introduced by 13bcc92274d52fa6df2d636c78cf6ea457d670aa. Instead of comparing only the beginning of a string with "rgb(", a full string compare was used. I also added some error handling to avoid crashing on noncompliant SVG files. Reviewed-by: Trond --- src/svg/qsvghandler.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index e2c3d92f21..35b8595e5c 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -810,24 +810,27 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler case 'r': { - // starts with "rgb(" - if (colorStrTr == QLatin1String("rgb(")) { + // starts with "rgb(", ends with ")" and consists of at least 7 characters "rgb(,,)" + if (colorStrTr.length() >= 7 && colorStrTr.at(colorStrTr.length() - 1) == QLatin1Char(')') + && QStringRef(colorStrTr.string(), colorStrTr.position(), 4) == QLatin1String("rgb(")) { const QChar *s = colorStrTr.constData() + 4; QVector compo = parseNumbersList(s); //1 means that it failed after reaching non-parsable //character which is going to be "%" if (compo.size() == 1) { - const QChar *s = colorStrTr.constData() + 4; + s = colorStrTr.constData() + 4; compo = parsePercentageList(s); - compo[0] *= (qreal)2.55; - compo[1] *= (qreal)2.55; - compo[2] *= (qreal)2.55; + for (int i = 0; i < compo.size(); ++i) + compo[i] *= (qreal)2.55; } - color = QColor(int(compo[0]), - int(compo[1]), - int(compo[2])); - return true; + if (compo.size() == 3) { + color = QColor(int(compo[0]), + int(compo[1]), + int(compo[2])); + return true; + } + return false; } } break; -- cgit v1.2.3