Packetizer: Correct packet length check

AA(1) + Old format(1)  + New Length(2) + New NetID(2) = 6
pull/32/head
Paul Hollinsky 2020-09-22 19:17:12 -04:00
parent 28b35a8243
commit 1f4358af4b
1 changed files with 2 additions and 2 deletions

View File

@ -75,12 +75,12 @@ bool Packetizer::input(const std::vector<uint8_t>& inputBytes) {
packet.network = Network((bytes[5] << 8) | bytes[4]); // Long packets have their netid stored as little endian on bytes 5 and 6 packet.network = Network((bytes[5] << 8) | bytes[4]); // Long packets have their netid stored as little endian on bytes 5 and 6
currentIndex += 4; currentIndex += 4;
/* Long packets can't have a length less than 4, because that would indicate a negative payload size. /* Long packets can't have a length less than 6, because that would indicate a negative payload size.
* Unlike the short packet length, the long packet length encompasses everything from the 0xAA to the * Unlike the short packet length, the long packet length encompasses everything from the 0xAA to the
* end of the payload. The short packet length, for reference, only encompasses the length of the actual * end of the payload. The short packet length, for reference, only encompasses the length of the actual
* payload, and not the header or checksum. * payload, and not the header or checksum.
*/ */
if(packetLength < 4 || packetLength > 4000) { if(packetLength < 6 || packetLength > 4000) {
bytes.pop_front(); bytes.pop_front();
EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error); EventManager::GetInstance().add(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
state = ReadState::SearchForHeader; state = ReadState::SearchForHeader;