wire: Reject messages with trailing bytes.#3645
Merged
davecgh merged 2 commits intodecred:masterfrom Mar 16, 2026
Merged
Conversation
jrick
approved these changes
Mar 12, 2026
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.
dc918ee to
57ba998
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.