Skip to content

Commit

Permalink
[8.1](backport #30658) Fix dissect trim panics from DELETE (\u007f) c…
Browse files Browse the repository at this point in the history
…haracter (#30868)

* Fix dissect trim panics from DELETE (\u007f) character (#30658)

Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657

(cherry picked from commit 9396deb)

Co-authored-by: Thomas Montague <[email protected]>
  • Loading branch information
mergify[bot] and montaguethomas authored Mar 17, 2022
1 parent 7eed8f7 commit 7f30bb3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...main[Check the HEAD dif
- Wildcard fields no longer have a default ignore_above setting of 1024. {issue}30096[30096] {pull}30668[30668]
- Ensure that the Reloadable part of beats are initialized before the Manager is started. {issue}30533[30533]
- Ignore bugfix version when running version compatibility check against Elasticsearch. {pull}30746[30746]
- Fix dissect trim panics from DELETE (127)(\u007f) character {issue}30657[30657] {pull}30658[30658]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/dissect/trim.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func newTrimmer(trimChars string, trimLeft, trimRight bool) (t trimmer, err erro
}

type asciiTrimmer struct {
chars [127]byte
chars [asciiLimit]byte
left, right bool
}

Expand Down
40 changes: 40 additions & 0 deletions libbeat/processors/dissect/trim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,46 @@ func TestTrimmer(t *testing.T) {
input: "\t\t༄𑅀߹꧁߹𑁍 ÿ",
expected: "༄𑅀߹꧁߹𑁍",
},
{ // demonstrates that unicode \u is converted to char in golang strings
name: "trim ASCII TILDE",
cutset: " ",
left: true,
right: true,
input: " hello world! \u007e ",
expected: "hello world! ~",
},
{
name: "trim ASCII DELETE",
cutset: " ",
left: true,
right: true,
input: " hello world! \u007f ",
expected: "hello world! \u007f",
},
{
name: "trim UTF-8 CONTROL",
cutset: " ",
left: true,
right: true,
input: " hello world! \u0080 ",
expected: "hello world! \u0080",
},
{
name: "trim ASCII DELETE cutset in UTF-8 input",
cutset: " \u007f",
left: true,
right: true,
input: " hello world! \u0080 \u007f",
expected: "hello world! \u0080",
},
{
name: "trim UTF-8 CONTROL cutset in UTF-8 input",
cutset: " \u0080",
left: true,
right: true,
input: " hello world! \u007f \u0080",
expected: "hello world! \u007f",
},
} {
t.Run(test.name, func(t *testing.T) {
trimmer, err := newTrimmer(test.cutset, test.left, test.right)
Expand Down

0 comments on commit 7f30bb3

Please sign in to comment.