From 7d16cae7183c3cf225bd4ad368b9d6d18c959e31 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 4 Sep 2021 15:57:31 +0300 Subject: [PATCH] Validate layout data. --- src/app/puzzle/xml/vplayoutfilereader.cpp | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/app/puzzle/xml/vplayoutfilereader.cpp b/src/app/puzzle/xml/vplayoutfilereader.cpp index d2456dba6..9bb8d6095 100644 --- a/src/app/puzzle/xml/vplayoutfilereader.cpp +++ b/src/app/puzzle/xml/vplayoutfilereader.cpp @@ -511,7 +511,10 @@ void VPLayoutFileReader::ReadSeamAllowance(const VPPiecePtr &piece) { if (not builtIn) { - // TODO add check if not empty + if (path.isEmpty()) + { + throw VException(tr("Error in line %1. Seam allowance is empty.").arg(lineNumber())); + } piece->SetSeamAllowancePoints(path); } } @@ -533,7 +536,10 @@ void VPLayoutFileReader::ReadGrainline(const VPPiecePtr &piece) QString arrowDirection = ReadAttributeEmptyString(attribs, ML::AttrArrowDirection); piece->SetGrainlineArrowType(StringToGrainlineArrowDirrection(arrowDirection)); - // TODO add check if not empty + if (path.isEmpty()) + { + throw VException(tr("Error in line %1. Grainline is empty.").arg(lineNumber())); + } piece->SetGrainlinePoints(path); } } @@ -614,8 +620,14 @@ auto VPLayoutFileReader::ReadInternalPath() -> VLayoutPiecePath QXmlStreamAttributes attribs = attributes(); path.SetCutPath(ReadAttributeBool(attribs, ML::AttrCut, falseStr)); path.SetPenStyle(LineStyleToPenStyle(ReadAttributeString(attribs, ML::AttrPenStyle, TypeLineLine))); - // TODO check if not empty - path.SetPoints(StringToPath(readElementText())); + + QVector shape = StringToPath(readElementText()); + if (shape.isEmpty()) + { + throw VException(tr("Error in line %1. Internal path shape is empty.").arg(lineNumber())); + } + + path.SetPoints(shape); return path; } @@ -658,7 +670,14 @@ auto VPLayoutFileReader::ReadMarker() -> VLayoutPlaceLabel marker.type = static_cast(ReadAttributeUInt(attribs, ML::AttrType, QChar('0'))); marker.center = StringToPoint(ReadAttributeEmptyString(attribs, ML::AttrCenter)); marker.box = StringToRect(ReadAttributeEmptyString(attribs, ML::AttrBox)); - marker.shape = StringToMarkerShape(readElementText()); + + PlaceLabelImg shape = StringToMarkerShape(readElementText()); + if (shape.isEmpty()) + { + throw VException(tr("Error in line %1. Marker shape is empty.").arg(lineNumber())); + } + + marker.shape = shape; return marker; }