From 1731aa1890eeaaf819c0e2e1bd729177734e6582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 10 Nov 2019 19:20:25 +0100 Subject: [PATCH] Added propper error handling --- src/data/gpiparser.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/data/gpiparser.cpp b/src/data/gpiparser.cpp index 01f12bc9..57696626 100644 --- a/src/data/gpiparser.cpp +++ b/src/data/gpiparser.cpp @@ -450,6 +450,7 @@ static quint32 readCamera(QDataStream &stream, QVector &waypoints, RecordHeader rh; quint8 flags, type, s7, rs; qint32 top, right, bottom, left; + quint32 ds = 15; rs = readRecordHeader(stream, rh); @@ -461,15 +462,14 @@ static quint32 readCamera(QDataStream &stream, QVector &waypoints, stream >> flags >> type >> s7; if (s7) { - int skip = s7 + 2 + s7/4; + quint32 skip = s7 + 2 + s7/4; stream.skipRawData(skip); qint32 lat = readInt24(stream); qint32 lon = readInt24(stream); - stream.skipRawData(rh.size - 12 - 3 - skip - 6); + ds += skip + 6; waypoints.append(Coordinates(toWGS24(lon), toWGS24(lat))); - } else - stream.skipRawData(rh.size - 15); + } Area area; Polygon polygon; @@ -498,6 +498,11 @@ static quint32 readCamera(QDataStream &stream, QVector &waypoints, polygons.append(area); + if (ds > rh.size) + stream.setStatus(QDataStream::ReadCorruptData); + else if (ds < rh.size) + stream.skipRawData(rh.size - ds); + return rs + rh.size; }