From f1e9983a58f769d7ddfffc3f22fa21094d720323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 6 Feb 2022 04:17:08 +0100 Subject: [PATCH] Fixed broken points(points labels) parsing --- src/map/IMG/lblfile.cpp | 31 +++++++++++++++---------------- src/map/IMG/lblfile.h | 12 ++++++------ src/map/IMG/rgnfile.cpp | 12 +++++++----- src/map/IMG/rgnfile.h | 2 +- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/map/IMG/lblfile.cpp b/src/map/IMG/lblfile.cpp index 546b2a02..b7a409e5 100644 --- a/src/map/IMG/lblfile.cpp +++ b/src/map/IMG/lblfile.cpp @@ -180,7 +180,7 @@ Label LBLFile::str2label(const QVector &str, bool capitalize, Shield(shieldType, _codec.toString(shieldLabel))); } -Label LBLFile::label6b(const SubFile *file, Handle &hdl, bool capitalize, +Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, bool capitalize, bool convert) const { Shield::Type shieldType = Shield::None; @@ -191,8 +191,8 @@ Label LBLFile::label6b(const SubFile *file, Handle &hdl, bool capitalize, int split = -1; while (true) { - if (!(file->readByte(hdl, &b1) && file->readByte(hdl, &b2) - && file->readByte(hdl, &b3))) + if (!(file->readByte(fileHdl, &b1) && file->readByte(fileHdl, &b2) + && file->readByte(fileHdl, &b3))) return Label(); int c[]= {b1>>2, (b1&0x3)<<4|b2>>4, (b2&0xF)<<2|b3>>6, b3&0x3F}; @@ -244,14 +244,14 @@ Label LBLFile::label6b(const SubFile *file, Handle &hdl, bool capitalize, } } -Label LBLFile::label8b(const SubFile *file, Handle &hdl, bool capitalize, +Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, bool capitalize, bool convert) const { QVector str; quint8 c; do { - if (!file->readByte(hdl, &c)) + if (!file->readByte(fileHdl, &c)) return Label(); str.append(c); } while (c); @@ -259,13 +259,12 @@ Label LBLFile::label8b(const SubFile *file, Handle &hdl, bool capitalize, return str2label(str, capitalize, convert); } -Label LBLFile::labelHuffman(const SubFile *file, Handle &hdl, bool capitalize, - bool convert) const +Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, + bool capitalize, bool convert) const { QVector str; - quint32 end = _offset + _size; - if (!_huffmanText->decode(file, hdl, end - pos(hdl), str)) + if (!_huffmanText->decode(file, fileHdl, 0xFFFFFFFF, str)) return Label(); if (!_table) return str2label(str, capitalize, convert); @@ -284,7 +283,7 @@ Label LBLFile::labelHuffman(const SubFile *file, Handle &hdl, bool capitalize, else if (str2.size()) str2.append(' '); - if (!_huffmanText->decode(file, hdl, end - off, str2)) + if (!_huffmanText->decode(this, hdl, _offset + _size - off, str2)) return Label(); } else { if (str.at(i) == 7) { @@ -320,20 +319,20 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize, if (!seek(hdl, labelOffset)) return Label(); - return label(this, hdl, capitalize, convert); + return label(hdl, this, hdl, capitalize, convert); } -Label LBLFile::label(const SubFile *file, Handle &hdl, bool capitalize, - bool convert) const +Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl, + bool capitalize, bool convert) const { switch (_encoding) { case 6: - return label6b(file, hdl, capitalize, convert); + return label6b(file, fileHdl, capitalize, convert); case 9: case 10: - return label8b(file, hdl, capitalize, convert); + return label8b(file, fileHdl, capitalize, convert); case 11: - return labelHuffman(file, hdl, capitalize, convert); + return labelHuffman(hdl, file, fileHdl, capitalize, convert); default: return Label(); } diff --git a/src/map/IMG/lblfile.h b/src/map/IMG/lblfile.h index 5eb6fb41..f2ecdbe7 100644 --- a/src/map/IMG/lblfile.h +++ b/src/map/IMG/lblfile.h @@ -33,8 +33,8 @@ public: Label label(Handle &hdl, quint32 offset, bool poi = false, bool capitalize = true, bool convert = false) const; - Label label(const SubFile *file, Handle &hdl, bool capitalize = true, - bool convert = false) const; + Label label(Handle &hdl, const SubFile *file, Handle &fileHdl, + bool capitalize = true, bool convert = false) const; quint8 imageIdSize() const {return _imgOffsetIdSize;} QPixmap image(Handle &hdl, quint32 id) const; @@ -47,12 +47,12 @@ private: Label str2label(const QVector &str, bool capitalize, bool convert) const; - Label label6b(const SubFile *file, Handle &hdl, bool capitalize, + Label label6b(const SubFile *file, Handle &fileHdl, bool capitalize, bool convert) const; - Label label8b(const SubFile *file, Handle &hdl, bool capitalize, - bool convert) const; - Label labelHuffman(const SubFile *file, Handle &hdl, bool capitalize, + Label label8b(const SubFile *file, Handle &fileHdl, bool capitalize, bool convert) const; + Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, + bool capitalize, bool convert) const; bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size, quint32 recordSize); diff --git a/src/map/IMG/rgnfile.cpp b/src/map/IMG/rgnfile.cpp index 6b7163aa..629bec9e 100644 --- a/src/map/IMG/rgnfile.cpp +++ b/src/map/IMG/rgnfile.cpp @@ -33,7 +33,7 @@ RGNFile::~RGNFile() } bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, - void *object, const LBLFile *lbl) const + void *object, const LBLFile *lbl, Handle &lblHdl) const { quint8 flags; quint32 rs; @@ -83,10 +83,11 @@ bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, if (point && (flags & 1) && lbl) { quint32 p = pos(hdl); - point->label = lbl->label(this, hdl); + point->label = lbl->label(lblHdl, this, hdl); point->classLabel = true; - rs -= (pos(hdl) - p); + Q_ASSERT(pos(hdl) - p <= rs + 4); + rs -= pos(hdl) - p; } return seek(hdl, pos(hdl) + rs); @@ -356,7 +357,8 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, if (subtype & 0x20 && !readUInt24(hdl, labelPtr)) return false; - if (subtype & 0x80 && !readClassFields(hdl, segmentType, &poly, lbl)) + if (subtype & 0x80 && !readClassFields(hdl, segmentType, &poly, lbl, + lblHdl)) return false; if (subtype & 0x40 && !skipLclFields(hdl, segmentType == Line ? _linesLclFlags : _polygonsLclFlags)) @@ -446,7 +448,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv, if (subtype & 0x20 && !readUInt24(hdl, labelPtr)) return false; - if (subtype & 0x80 && !readClassFields(hdl, Point, &point, lbl)) + if (subtype & 0x80 && !readClassFields(hdl, Point, &point, lbl, lblHdl)) return false; if (subtype & 0x40 && !skipLclFields(hdl, _pointsLclFlags)) return false; diff --git a/src/map/IMG/rgnfile.h b/src/map/IMG/rgnfile.h index fcc6c7e2..3a12daa6 100644 --- a/src/map/IMG/rgnfile.h +++ b/src/map/IMG/rgnfile.h @@ -63,7 +63,7 @@ public: private: bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const; bool readClassFields(Handle &hdl, SegmentType segmentType, void *object, - const LBLFile *lbl) const; + const LBLFile *lbl, Handle &lblHdl) const; bool skipLclFields(Handle &hdl, const quint32 flags[3]) const; bool skipGblFields(Handle &hdl, quint32 flags) const;