From 5cd0a3a8b0ca43309fe1eb46284c7d86ec443676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 12 May 2019 00:10:56 +0200 Subject: [PATCH] Properly parse TRE7 section --- src/map/IMG/trefile.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/map/IMG/trefile.cpp b/src/map/IMG/trefile.cpp index fce68395..bbe73dd9 100644 --- a/src/map/IMG/trefile.cpp +++ b/src/map/IMG/trefile.cpp @@ -180,14 +180,17 @@ bool TREFile::init() } // objects with extended types (TRE7) - if (extSize && extItemSize == 13) { + if (extSize && extItemSize >= 12 + && (sl.size() - (int)(extSize/extItemSize) + 1 >= 0)) { quint32 polygons, lines, points; - quint8 kinds; if (!seek(hdl, extOffset)) return false; - for (int i = 0; i < sl.size(); i++) { + + for (int i = sl.size() - (extSize/extItemSize) + 1; i < sl.size(); i++) { if (!(readUInt32(hdl, polygons) && readUInt32(hdl, lines) - && readUInt32(hdl, points) && readByte(hdl, kinds))) + && readUInt32(hdl, points))) + return false; + if (!seek(hdl, hdl.pos + extItemSize - 12)) return false; if (i && sl.at(i-1)) sl.at(i-1)->setExtEnds(polygons, lines, points);