fix(codecs): correct operand order in octet-counting framer underflow#25657
Open
hhh6593 wants to merge 2 commits into
Open
fix(codecs): correct operand order in octet-counting framer underflow#25657hhh6593 wants to merge 2 commits into
hhh6593 wants to merge 2 commits into
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
This comment has been minimized.
This comment has been minimized.
c65b448 to
f26b05b
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
f26b05b to
a12a937
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.
Summary
While reading through the octet-counting framer (RFC 6587, used by the TCP
syslogsource) I noticed that the "discard the rest of an over-length frame" branch computes the remaining bytes assrc.len() - chars. That branch only runs whensrc.len() < chars, so the subtraction always underflows. In debug builds it panics; in release it wraps to a value nearusize::MAX, which leaves the decoder stuck in theDiscardingstate forever and silently drops every byte that arrives afterwards on that connection. The intent is clearly the other way around — how many bytes are still left to discard after consuming this buffer — so the fix is just swapping the operands tochars - src.len().This only shows up when an over-length, length-prefixed message is split across multiple reads, which is normal TCP fragmentation, so it's reachable from untrusted input.
Vector configuration
A TCP syslog source with a small
max_lengthsends over-length frames down the discard path; an over-length message that arrives split across reads then hits the bug.How did you test this PR?
I added a regression test (octet_decode_discard_partial_frame_underflow) that drives the decoder into the Discarding state with an over-length frame and then feeds a small follow-up chunk so that src.len() < chars, which reproduces the underflow on the current code. After the fix the whole module is green:
Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
Notes
@vectordotdev/vectorto reach out to us regarding this PR.pre-pushhook, please see this template.make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make testgit merge origin masterandgit push.Cargo.lock), pleaserun
make build-licensesto regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.