|
| 1 | +From 2cea7c730d27e252186cdae3a74c34897d43f566 Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Wed, 17 Dec 2025 05:03:42 +0000 |
| 4 | +Subject: [PATCH] Fields over 65535 bytes noe encoded correctly |
| 5 | + |
| 6 | +When encoding strings (1.5.3 in spec), and some other variable length fields, if the user passed in more then 65535 bytes the ouput would not be as expected (due to 16 byte header there is a hard limit). This change truncates output to 65535 bytes. |
| 7 | + |
| 8 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 9 | +Upstream-reference: AI Backport of https://patch-diff.githubusercontent.com/raw/eclipse-paho/paho.mqtt.golang/pull/714.patch |
| 10 | +--- |
| 11 | + .../github.com/eclipse/paho.mqtt.golang/packets/packets.go | 5 +++++ |
| 12 | + 1 file changed, 5 insertions(+) |
| 13 | + |
| 14 | +diff --git a/vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go b/vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go |
| 15 | +index 42eeb46..c185c83 100644 |
| 16 | +--- a/vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go |
| 17 | ++++ b/vendor/github.com/eclipse/paho.mqtt.golang/packets/packets.go |
| 18 | +@@ -304,6 +304,11 @@ func decodeBytes(b io.Reader) ([]byte, error) { |
| 19 | + } |
| 20 | + |
| 21 | + func encodeBytes(field []byte) []byte { |
| 22 | ++ // Attempting to encode more than 65,535 bytes would lead to an unexpected 16-bit length and extra data written |
| 23 | ++ // (which would be parsed as later parts of the message). The safest option is to truncate. |
| 24 | ++ if len(field) > 65535 { |
| 25 | ++ field = field[0:65535] |
| 26 | ++ } |
| 27 | + fieldLength := make([]byte, 2) |
| 28 | + binary.BigEndian.PutUint16(fieldLength, uint16(len(field))) |
| 29 | + return append(fieldLength, field...) |
| 30 | +-- |
| 31 | +2.45.4 |
| 32 | + |
0 commit comments