add a bug check for consistent payload length in the packet packer

This commit is contained in:
Marten Seemann
2019-08-10 14:57:39 +07:00
parent 1f950da751
commit fc77dee22d

View File

@@ -546,6 +546,9 @@ func (p *packetPacker) writeAndSealPacketWithPadding(
}
}
if payloadSize := protocol.ByteCount(buffer.Len()-payloadOffset) - paddingLen; payloadSize != payload.length {
return nil, fmt.Errorf("PacketPacker BUG: payload size inconsistent (expected %d, got %d bytes)", payload.length, payloadSize)
}
if size := protocol.ByteCount(buffer.Len() + sealer.Overhead()); size > p.maxPacketSize {
return nil, fmt.Errorf("PacketPacker BUG: packet too large (%d bytes, allowed %d bytes)", size, p.maxPacketSize)
}