Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dissect trim panics from unicode DELETE (\u007f) char #30657

Closed
montaguethomas opened this issue Mar 2, 2022 · 1 comment · Fixed by #30658
Closed

Dissect trim panics from unicode DELETE (\u007f) char #30657

montaguethomas opened this issue Mar 2, 2022 · 1 comment · Fixed by #30658
Labels
bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@montaguethomas
Copy link
Contributor

montaguethomas commented Mar 2, 2022

We hit a panic with parsing logs using dissect with trim when a line had a DELETE (127)(\u007f) character at the end of the line.

  • Version: 7.17.0 (affects 7.9 and later)
  • Operating System: Linux
  • Steps to Reproduce: Test below
panic: runtime error: index out of range [127] with length 127

goroutine 52 [running]:
github.com/elastic/beats/v7/libbeat/processors/dissect.asciiTrimmer.Trim(...)
	/go/src/github.com/elastic/beats/libbeat/processors/dissect/trim.go:66
github.com/elastic/beats/v7/libbeat/processors/dissect.(*Dissector).Dissect(0xc000a0da40, 0xc001517d10, 0xe5, 0x108528980, 0xc0015b1060, 0x0)
	/go/src/github.com/elastic/beats/libbeat/processors/dissect/dissect.go:73 +0x104
github.com/elastic/beats/v7/libbeat/processors/dissect.(*processor).Run(0xc0005b5280, 0xc0015c81c0, 0x107d95b74, 0x1e, 0xc000b8bad0)
	/go/src/github.com/elastic/beats/libbeat/processors/dissect/processor.go:91 +0x3e5

Test to trigger the panic:

func TestTrimmer(t *testing.T) {
	for _, test := range []struct {
		name, cutset    string
		left, right     bool
		input, expected string
	}{
		{
			name:     "trim both with unicode",
			cutset:   " ",
			left:     true,
			right:    true,
			input:    "  hello world! \u007f ",
			expected: "hello world! \u007f",
		},
	} {
		t.Run(test.name, func(t *testing.T) {
			trimmer, err := newTrimmer(test.cutset, test.left, test.right)
			if !assert.NoError(t, err) {
				return
			}
			start, end := trimmer.Trim(test.input, 0, len(test.input))
			output := test.input[start:end]
			assert.Equal(t, test.expected, output)
		})
	}
}
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Mar 2, 2022
@jsoriano jsoriano added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Mar 15, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Mar 15, 2022
@jlind23 jlind23 added the bug label Mar 15, 2022
adriansr pushed a commit that referenced this issue Mar 16, 2022
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657
mergify bot pushed a commit that referenced this issue Mar 16, 2022
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657

(cherry picked from commit 9396deb)
mergify bot pushed a commit that referenced this issue Mar 16, 2022
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657

(cherry picked from commit 9396deb)
mergify bot pushed a commit that referenced this issue Mar 16, 2022
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657

(cherry picked from commit 9396deb)
adriansr pushed a commit that referenced this issue Mar 17, 2022
…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 <montague.thomas@gmail.com>
adriansr pushed a commit that referenced this issue Mar 17, 2022
…haracter (#30867)

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

Closes #30657

(cherry picked from commit 9396deb)

Co-authored-by: Thomas Montague <montague.thomas@gmail.com>
adriansr pushed a commit that referenced this issue Mar 17, 2022
…character (#30866)

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

Closes #30657

(cherry picked from commit 9396deb)

Co-authored-by: Thomas Montague <montague.thomas@gmail.com>
kush-elastic pushed a commit to kush-elastic/beats that referenced this issue May 2, 2022
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes elastic#30657
leweafan pushed a commit to leweafan/beats that referenced this issue Apr 28, 2023
…007f) character (elastic#30867)

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

Closes elastic#30657

(cherry picked from commit 70298dd)

Co-authored-by: Thomas Montague <montague.thomas@gmail.com>
chrisberkhout pushed a commit that referenced this issue Jun 1, 2023
Fixes an index out of range panic with asciiTrimmer.Trim().

Closes #30657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants