MQTT: unsigned integer underflow bypasses MAX_MQTT_MESSAGE_SIZE check
An unsigned integer underflow in libcurl's MQTT publish size check lets a caller set a declared payload size larger than the maximum while supplying a much smaller buffer, so the oversized message is not rejected. With AddressSanitizer enabled, libcurl then performs an out-of-bounds read in the MQTT publish routine, causing a crash or abort.
Originally disclosed on HackerOne
- Disclosed after 3 hours
Summary
An unsigned integer underflow exists in libcurl's MQTT publish path. Due to incorrect arithmetic ordering in the size validation logic, oversized MQTT PUBLISH messages are not rejected as intended.
Affected version
libcurl 8.18.0 Tested on macOS (arm64) with AddressSanitizer enabled.
Steps To Reproduce
- Start a minimal MQTT server that accepts a CONNECT and CONNACK.
- Use libcurl with the mqtt:// scheme.
- Set CURLOPT_POSTFIELDSIZE_LARGE to a value larger than MAX_MQTT_MESSAGE_SIZE.
- Provide a much smaller buffer via CURLOPT_POSTFIELDS.
- Call curl_easy_perform( ).
libcurl proceeds instead of returning CURLE_TOO_LARGE, and ASAN reports an out-of-bounds read in mqtt_publish().
Supporting Material / References
- ASAN stack trace showing heap-buffer-overflow in mqtt_publish()
- PoC client and server source code attached
sql
Impact
Summary:
Summary
This issue allows applications using libcurl MQTT to bypass the intended MAX_MQTT_MESSAGE_SIZE enforcement.
If CURLOPT_POSTFIELDSIZE_LARGE does not match the actual buffer size, libcurl may perform out-of-bounds memory reads, leading to crashes or aborts (confirmed with ASAN).
No direct remote exploitation was identified.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely an unsigned integer underflow caused by incorrect arithmetic ordering in the MQTT publish size validation, so the comparison against the maximum size does not reject oversized declared lengths.
Impact
Applications using libcurl's MQTT support can bypass the intended maximum message size check, and when the declared size does not match the actual buffer, libcurl may read out of bounds and crash or abort; no direct remote exploitation was identified.
What the attacker needed
Attacker controls the calling application; declared size exceeds the maximum; buffer smaller than declared size
How it was found
- Start a minimal MQTT server that accepts a CONNECT and CONNACK.
- Use libcurl with the mqtt:// scheme.
- Set CURLOPT_POSTFIELDSIZE_LARGE to a value larger than MAX_MQTT_MESSAGE_SIZE.
- Provide a much smaller buffer via CURLOPT_POSTFIELDS.
- Call curl_easy_perform().
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
libcurl is a library programs use to talk to servers, and MQTT is a lightweight messaging protocol. The library is meant to refuse messages above a maximum size, but a counting mistake in the check means a caller can claim a huge size while handing over a small buffer, and the library reads past the end of that buffer. Reading past a buffer's end is an out-of-bounds read, which can crash the program.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.