paho.ReadPacket Parket size should be limited to `Maximum Packet Size` (if set)
#336 opened on May 30, 2026
Repository metrics
- Stars
- (437 stars)
- PR merge metrics
- (PR metrics pending)
Description
Currently a hostile broker could (potentially) cause a client to run out of memory by sending a lot of 256MB messages. I feel the risk is fairly low because the attacker would need to control the broker, and be able to deliver messages quickly enough to overwhelm the client.
The CONNECT packet can include a Maximum Packet Size property. If this has been set then, ideally, paho.ReadPacket should reject any packets larger than this (ideally as soon as it receives the packet size so no memory is allocated). As per the spec, upon receiving an oversize packet, "the Client uses DISCONNECT with Reason Code 0x95 (Packet too large), as described in section 4.13".
The cleanest way of implementing this is probably to add a paho.ReadPacketN (or similar) that takes the reader and a maximum size. The existing function can then just call the new one (ReadPacket is also used when reading from disk).