[pkg/stanza] Fix issue where syslog octet parsing could truncate token #27294
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.
This fixes a bug detected while attempting to migrate test to the new
splittest
framework.Generally speaking, the responsibility of a
bufio.SplitFunc
is to parse a token from a given buffer ([]byte
). However, the split func does not have control over the size of the buffer, so it must be able to ask for more data. The mechanism for asking for more data is to return0, nil, nil
.A split func is also told whether there is any more data to read. This allows it to chose whether to "give up" and return a truncated token, or to insist that it will wait until there is more data (which may never happen).
This particular function is parsing tokens based on a simple numerical prefix which indicates how long the token will be.
e.g.
54 This is the actual token and it is 54 characters long.
The problem is that the function would give up prematurely and return a truncated token. The proper behavior is to ask for more data unless the function is specifically told that there is no more data to receive.
This fixes the behavior so that whenever we are able to parse an expected length but find there is not enough data in the buffer to fulfill the expectation, we ask for more data. It only returns a truncated token when there is no more data to ask for.