diff --git a/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp index d08ce9c1..e7be2913 100644 --- a/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/linked_contour_vector_packet.cpp @@ -97,20 +97,18 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector coordinate - int vectorCount = vectorSize / 4; - int16_t endI; - int16_t endJ; + int vectorCount = vectorSize / 4; + + p->endI_.resize(vectorCount); + p->endJ_.resize(vectorCount); for (int v = 0; v < vectorCount && !is.eof(); v++) { - is.read(reinterpret_cast(&endI), 2); - is.read(reinterpret_cast(&endJ), 2); + is.read(reinterpret_cast(&p->endI_[v]), 2); + is.read(reinterpret_cast(&p->endJ_[v]), 2); - endI = ntohs(endI); - endJ = ntohs(endJ); - - p->endI_.push_back(endI); - p->endJ_.push_back(endJ); + p->endI_[v] = ntohs(p->endI_[v]); + p->endJ_[v] = ntohs(p->endJ_[v]); } if (is.eof()) diff --git a/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp index a026252b..344fcbcb 100644 --- a/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/linked_vector_packet.cpp @@ -110,20 +110,18 @@ bool LinkedVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector coordinate - int vectorCount = vectorSize / 4; - int16_t endI; - int16_t endJ; + int vectorCount = vectorSize / 4; + + p->endI_.resize(vectorCount); + p->endJ_.resize(vectorCount); for (int v = 0; v < vectorCount && !is.eof(); v++) { - is.read(reinterpret_cast(&endI), 2); - is.read(reinterpret_cast(&endJ), 2); + is.read(reinterpret_cast(&p->endI_[v]), 2); + is.read(reinterpret_cast(&p->endJ_[v]), 2); - endI = ntohs(endI); - endJ = ntohs(endJ); - - p->endI_.push_back(endI); - p->endJ_.push_back(endJ); + p->endI_[v] = ntohs(p->endI_[v]); + p->endJ_[v] = ntohs(p->endJ_[v]); } if (is.eof()) diff --git a/wxdata/source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp index cefa5db5..baf3a633 100644 --- a/wxdata/source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/text_and_special_symbol_packet.cpp @@ -80,26 +80,15 @@ bool TextAndSpecialSymbolPacket::Parse(std::istream& is) { bool blockValid = true; + std::streampos isBegin = is.tellg(); + is.read(reinterpret_cast(&p->packetCode_), 2); is.read(reinterpret_cast(&p->lengthOfBlock_), 2); p->packetCode_ = ntohs(p->packetCode_); p->lengthOfBlock_ = ntohs(p->lengthOfBlock_); - int vectorSize = static_cast(p->lengthOfBlock_) - 4; - - if (is.eof()) - { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; - blockValid = false; - } - else if (p->packetCode_ == 8) - { - is.read(reinterpret_cast(&p->valueOfText_), 2); - p->valueOfText_ = ntohs(p->valueOfText_); - - vectorSize -= 2; - } + int textLength = static_cast(p->lengthOfBlock_) - 4; is.read(reinterpret_cast(&p->startI_), 2); is.read(reinterpret_cast(&p->startJ_), 2); @@ -107,17 +96,6 @@ bool TextAndSpecialSymbolPacket::Parse(std::istream& is) p->startI_ = ntohs(p->startI_); p->startJ_ = ntohs(p->startJ_); - // The number of vectors is equal to the size divided by the number of bytes - // in a vector coordinate - int vectorCount = vectorSize; - char c; - - for (int v = 0; v < vectorCount && !is.eof(); v++) - { - is.get(c); - p->characters_.push_back(c); - } - if (is.eof()) { BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; @@ -131,6 +109,39 @@ bool TextAndSpecialSymbolPacket::Parse(std::istream& is) << logPrefix_ << "Invalid packet code: " << p->packetCode_; blockValid = false; } + else if (p->lengthOfBlock_ < 1 || p->lengthOfBlock_ > 32767) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Invalid length of block: " << p->packetCode_; + blockValid = false; + } + else if (p->packetCode_ == 8) + { + is.read(reinterpret_cast(&p->valueOfText_), 2); + p->valueOfText_ = ntohs(p->valueOfText_); + + textLength -= 2; + } + } + + if (blockValid && textLength < 0) + { + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Too few bytes in block: " << p->lengthOfBlock_; + blockValid = false; + } + + if (blockValid) + { + p->characters_.resize(textLength); + is.read(reinterpret_cast(p->characters_.data()), textLength); + } + + std::streampos isEnd = is.tellg(); + + if (!ValidateMessage(is, isEnd - isBegin)) + { + blockValid = false; } return blockValid; diff --git a/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp index e9d636d0..6ce7e9c2 100644 --- a/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/unlinked_contour_vector_packet.cpp @@ -80,28 +80,24 @@ bool UnlinkedContourVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector - int vectorCount = vectorSize / 8; - int16_t beginI; - int16_t beginJ; - int16_t endI; - int16_t endJ; + int vectorCount = vectorSize / 8; + + p->beginI_.resize(vectorCount); + p->beginJ_.resize(vectorCount); + p->endI_.resize(vectorCount); + p->endJ_.resize(vectorCount); for (int v = 0; v < vectorCount && !is.eof(); v++) { - is.read(reinterpret_cast(&beginI), 2); - is.read(reinterpret_cast(&beginJ), 2); - is.read(reinterpret_cast(&endI), 2); - is.read(reinterpret_cast(&endJ), 2); + is.read(reinterpret_cast(&p->beginI_[v]), 2); + is.read(reinterpret_cast(&p->beginJ_[v]), 2); + is.read(reinterpret_cast(&p->endI_[v]), 2); + is.read(reinterpret_cast(&p->endJ_[v]), 2); - beginI = ntohs(beginI); - beginJ = ntohs(beginJ); - endI = ntohs(endI); - endJ = ntohs(endJ); - - p->beginI_.push_back(beginI); - p->beginJ_.push_back(beginJ); - p->endI_.push_back(endI); - p->endJ_.push_back(endJ); + p->beginI_[v] = ntohs(p->beginI_[v]); + p->beginJ_[v] = ntohs(p->beginJ_[v]); + p->endI_[v] = ntohs(p->endI_[v]); + p->endJ_[v] = ntohs(p->endJ_[v]); } if (is.eof()) diff --git a/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp b/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp index 18092d92..a891f680 100644 --- a/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp +++ b/wxdata/source/scwx/wsr88d/rpg/unlinked_vector_packet.cpp @@ -105,28 +105,24 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) // The number of vectors is equal to the size divided by the number of bytes // in a vector - int vectorCount = vectorSize / 8; - int16_t beginI; - int16_t beginJ; - int16_t endI; - int16_t endJ; + int vectorCount = vectorSize / 8; + + p->beginI_.resize(vectorCount); + p->beginJ_.resize(vectorCount); + p->endI_.resize(vectorCount); + p->endJ_.resize(vectorCount); for (int v = 0; v < vectorCount && !is.eof(); v++) { - is.read(reinterpret_cast(&beginI), 2); - is.read(reinterpret_cast(&beginJ), 2); - is.read(reinterpret_cast(&endI), 2); - is.read(reinterpret_cast(&endJ), 2); + is.read(reinterpret_cast(&p->beginI_[v]), 2); + is.read(reinterpret_cast(&p->beginJ_[v]), 2); + is.read(reinterpret_cast(&p->endI_[v]), 2); + is.read(reinterpret_cast(&p->endJ_[v]), 2); - beginI = ntohs(beginI); - beginJ = ntohs(beginJ); - endI = ntohs(endI); - endJ = ntohs(endJ); - - p->beginI_.push_back(beginI); - p->beginJ_.push_back(beginJ); - p->endI_.push_back(endI); - p->endJ_.push_back(endJ); + p->beginI_[v] = ntohs(p->beginI_[v]); + p->beginJ_[v] = ntohs(p->beginJ_[v]); + p->endI_[v] = ntohs(p->endI_[v]); + p->endJ_[v] = ntohs(p->endJ_[v]); } if (is.eof())