1
0
mirror of https://github.com/qt/qtmqtt.git synced 2026-10-25 16:16:26 +00:00
Go to file
Tatiana Borisova 06d301aa50 Read the Remaining Length as a variable byte integer everywhere
- Every MQTT packet begins with a fixed header, whose second field is the
Remaining Length: the number of bytes that follow. It is not a byte. It
is spread over one to four bytes, seven value bits each, with the top
bit meaning "another byte follows". So values up to 127 take one byte,
and larger values take more.

Six packet types read it as a single quint8: SUBACK, UNSUBACK, PUBACK,
PUBREC, PUBREL and PUBCOMP. For most of them that used to be correct.
In MQTT 3.1.1 those packets contain nothing but a two byte identifier,
so the length was always exactly 2, which always fits in one byte. The
code did not even use the byte it read: it checked that the value was 2
and then hardcoded the length.

MQTT 5.0 support (ac66658) gave those packets an optional reason code
and properties, so the length can now be far above 127. That commit
switched off the "must be 2" check for MQTT 5.0 and began using the
byte as the real length, but kept reading only one byte. The check had
been the only thing making a one byte read safe, because a multi-byte
length always has its top bit set and so could never equal 2.

SUBACK never had a fixed length at all, since its payload carries one
reason code per subscribed topic filter. It has been misparsed for any
SUBACK above 127 bytes since the parser was written (d96011b).

Reading one byte of a two byte length consumes one byte too few, so the
remainder of the packet is then read as the next packet's header. The
client rejects a valid acknowledgement and stays out of step for the
rest of the connection. Brokers trigger this on ordinary traffic as
soon as they attach a reason string or user properties.

All six now use readVariableByteInteger(), and each rejects a length too
short to hold the fields the specification requires.

PUBREL also accepted a length of exactly 2 even for MQTT 5.0, which
rejected valid PUBREL packets carrying a reason code. It now accepts 2
or more there, and still requires exactly 2 for MQTT 3.1.1.

- Adds three regression tests driving the parser through the existing
FakeServer, so they need no broker.

Pick-to: 6.11 6.12 6.8
Task-number: QTBUG-149569
Change-Id: Ib239d836556e0cc14e13c116dee757fdd1a7ae81
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2026-09-01 17:40:37 +00:00
coin Update to coin_module_test_template_v3.yaml 2026-08-17 09:51:21 +00:00
dist Remove year from Qt Copyright in REUSE.toml 2025-07-09 11:01:49 +02:00
examples Doc: Add alt text for \image tags for qtmqtt 2026-03-11 14:32:53 +01:00
LICENSES Add REUSE.toml files and missing licenses 2024-11-14 12:24:58 +00:00
src Read the Remaining Length as a variable byte integer everywhere 2026-09-01 17:40:37 +00:00
tests Read the Remaining Length as a variable byte integer everywhere 2026-09-01 17:40:37 +00:00
.cmake.conf Bump version to 6.13.0 2026-06-04 21:59:51 +00:00
.gitattributes Initial commit 2017-01-19 10:27:05 +01:00
.gitignore Add CMakeUserPresets.json to .gitignore 2024-11-28 18:02:47 +01:00
.gitreview Add .gitreview file 2025-03-24 15:22:02 +01:00
.tag Initial commit 2017-01-19 10:27:05 +01:00
CMakeLists.txt Move qt_internal_project_setup as early as possible 2025-06-20 15:33:39 +02:00
CONTRIBUTING.md Add CONTRIBUTING.md file 2026-04-21 07:22:04 +00:00
dependencies.yaml Update dependencies on 'dev' in qt/qtmqtt 2026-09-01 00:54:22 +00:00
licenseRule.json Add CONTRIBUTING.md file 2026-04-21 07:22:04 +00:00
REUSE.toml Add CONTRIBUTING.md file 2026-04-21 07:22:04 +00:00