* Reads the packet size from the raw packet and stores it in the packet->size * @return True iff the packet size seems plausible. */
| 257 | * @return True iff the packet size seems plausible. |
| 258 | */ |
| 259 | bool Packet::ParsePacketSize() |
| 260 | { |
| 261 | size_t size = static_cast<size_t>(this->buffer[0]); |
| 262 | size += static_cast<size_t>(this->buffer[1]) << 8; |
| 263 | |
| 264 | /* If the size of the packet is less than the bytes required for the size and type of |
| 265 | * the packet, or more than the allowed limit, then something is wrong with the packet. |
| 266 | * In those cases the packet can generally be regarded as containing garbage data. */ |
| 267 | if (size < EncodedLengthOfPacketSize() + EncodedLengthOfPacketType() || size > this->limit) return false; |
| 268 | |
| 269 | this->buffer.resize(size); |
| 270 | this->pos = static_cast<PacketSize>(EncodedLengthOfPacketSize()); |
| 271 | return true; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Prepares the packet so it can be read |
no test coverage detected