Skip to content

wire: Reject messages with trailing bytes.#3645

Merged
davecgh merged 2 commits intodecred:masterfrom
davecgh:wire_discard_trailing
Mar 16, 2026
Merged

wire: Reject messages with trailing bytes.#3645
davecgh merged 2 commits intodecred:masterfrom
davecgh:wire_discard_trailing

Conversation

@davecgh
Copy link
Member

@davecgh davecgh commented Mar 12, 2026

Currently, message decoding correctly reads exactly the amount of bytes that are needed and silently ignores any remaining bytes. This is correct and expected behavior, however, the entire raw buffer is also passed through to rest of the application code unaltered (aka with the extra trailing bytes) for use in some very specific cases.

While there are no serious consequences to this behavior currently, it is not ideal and could potentially lead to unexpected consequences in the future.

With that in mind, this adds an additional safety check to reject any messages that are not fully consumed while decoding to prevent them immediately at the protocol level rather than leaving it to code at higher layers to deal with.

While here, it also improves the read message error path tests to improve their accuracy, modernize the error detection, and make them more consistent with the newer formatting practices in a separate commit.

@davecgh davecgh added this to the 2.2.0 milestone Mar 12, 2026
davecgh added 2 commits March 12, 2026 16:25
This updates the tests which exercise various read message error paths
to improve their accuracy, modernize the error detection, and make them
more consistent with the newer formatting practices.
Currently, message decoding correctly reads exactly the amount of bytes
that are needed and silently ignores any remaining bytes.  This is
correct and expected behavior, however, the entire raw buffer is also
passed through to rest of the application code unaltered (aka with the
extra trailing bytes) for use in some very specific cases.

While there are no serious consequences to this behavior currently, it
is not ideal and could potentially lead to unexpected consequences in
the future.

With that in mind, this adds an additional safety check to reject any
messages that are not fully consumed while decoding to prevent them
immediately at the protocol level rather than leaving it to code at
higher layers to deal with.
@davecgh davecgh force-pushed the wire_discard_trailing branch from dc918ee to 57ba998 Compare March 12, 2026 21:27
@davecgh davecgh merged commit 5efa7c2 into decred:master Mar 16, 2026
32 checks passed
@davecgh davecgh deleted the wire_discard_trailing branch March 16, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants