|
| 1 | +From 8facc4d18c3aa37db07861d3085051f45db72f6a Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Mon, 8 Dec 2025 12:25:03 +0000 |
| 4 | +Subject: [PATCH] Fields over 65535 bytes now encoded correctly |
| 5 | + |
| 6 | +When encoding strings (1.5.3 in spec), and some other variable length fields, if the user passed in more than 65535 bytes the output 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://github.com/eclipse-paho/paho.mqtt.golang/commit/3162447fa892038e82256e918b681dc0c63a21ff.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 b2d7ed1b..7cc3c6d8 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 | +@@ -330,6 +330,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