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

input buffer is mess up if charset decode error #2416

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions filebeat/harvester/reader/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (l *Line) advance() error {
sz, err := l.decode(idx + len(l.nl))
if err != nil {
logp.Err("Error decoding line: %s", err)
sz = idx + len(l.nl)
}

// consume transformed bytes from input buffer
Expand All @@ -157,19 +158,20 @@ func (l *Line) decode(end int) (int, error) {
var nDst, nSrc int

nDst, nSrc, err = l.decoder.Transform(buffer, inBytes[start:end], false)

start += nSrc

l.outBuffer.Write(buffer[:nDst])

if err != nil {
if err == transform.ErrShortDst { // continue transforming
// Reset error as decoding continues
err = nil
start += nSrc
l.outBuffer.Write(buffer[:nDst])
continue
}
l.outBuffer.Write(inBytes[0:end])
start = end
break
}
start += nSrc
l.outBuffer.Write(buffer[:nDst])
}

l.byteCount += start
Expand Down