From c5e1872c2eef176774a3aba0d39f959ff39f656a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 13 Jul 2021 17:31:37 +0200 Subject: [PATCH] Fixed "float font sizes causing crash on style load" issue --- src/map/mapsforge/style.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/map/mapsforge/style.cpp b/src/map/mapsforge/style.cpp index d491bb5b..41581544 100644 --- a/src/map/mapsforge/style.cpp +++ b/src/map/mapsforge/style.cpp @@ -156,6 +156,7 @@ void Style::text(QXmlStreamReader &reader, const Rule &rule, int fontSize = 9; bool bold = false, italic = false; QString fontFamily("Helvetica"); + bool ok; if (attr.hasAttribute("k")) ri._key = attr.value("k").toLatin1(); @@ -163,10 +164,21 @@ void Style::text(QXmlStreamReader &reader, const Rule &rule, ri._fillColor = QColor(attr.value("fill").toString()); if (attr.hasAttribute("stroke")) ri._strokeColor = QColor(attr.value("stroke").toString()); - if (attr.hasAttribute("stroke-width")) - ri._strokeWidth = attr.value("stroke-width").toFloat(); - if (attr.hasAttribute("font-size")) - fontSize = attr.value("font-size").toInt(); + if (attr.hasAttribute("stroke-width")) { + ri._strokeWidth = attr.value("stroke-width").toFloat(&ok); + if (!ok || ri._strokeWidth < 0) { + reader.raiseError(attr.value("stroke-width") + + ": invalid stroke-width"); + return; + } + } + if (attr.hasAttribute("font-size")) { + fontSize = attr.value("font-size").toFloat(&ok); + if (!ok || fontSize < 0) { + reader.raiseError(attr.value("font-size") + ": invalid font-size"); + return; + } + } if (attr.hasAttribute("font-style")) { QString style(attr.value("font-style").toString()); if (style == "bold") @@ -192,8 +204,9 @@ void Style::text(QXmlStreamReader &reader, const Rule &rule, ri._font.setItalic(italic); - for (int i = 0; i < lists.size(); i++) - lists[i]->append(ri); + if (fontSize) + for (int i = 0; i < lists.size(); i++) + lists[i]->append(ri); reader.skipCurrentElement(); }