Skip to content

Find, verify, and analyze leaked credentials

Clarify "no decoder found for chunk" log message (#3001)

Richard Gomezb7411d292231
diff --git a/pkg/decoders/base64.go b/pkg/decoders/base64.go
index 8d19e7eb5..dcf78cc8a 100644
--- a/pkg/decoders/base64.go
+++ b/pkg/decoders/base64.go
@@ -27,6 +27,10 @@ func init() {
}
}
+func (d *Base64) Type() detectorspb.DecoderType {
+ return detectorspb.DecoderType_BASE64
+}
+
func (d *Base64) FromChunk(chunk *sources.Chunk) *DecodableChunk {
decodableChunk := &DecodableChunk{Chunk: chunk, DecoderType: d.Type()}
encodedSubstrings := getSubstringsOfCharacterSet(chunk.Data, 20, b64CharsetMapping, b64EndChars)
@@ -67,10 +71,6 @@ func (d *Base64) FromChunk(chunk *sources.Chunk) *DecodableChunk {
return nil
}
-func (d *Base64) Type() detectorspb.DecoderType {
- return detectorspb.DecoderType_BASE64
-}
-
func isASCII(b []byte) bool {
for i := 0; i < len(b); i++ {
if b[i] > unicode.MaxASCII {
diff --git a/pkg/decoders/escaped_unicode.go b/pkg/decoders/escaped_unicode.go
index b47d9383f..f1a523f23 100644
--- a/pkg/decoders/escaped_unicode.go
+++ b/pkg/decoders/escaped_unicode.go
@@ -24,6 +24,10 @@ var (
escapePat = regexp.MustCompile(`(?i:\\{1,2}u)([a-fA-F0-9]{4})`)
)
+func (d *EscapedUnicode) Type() detectorspb.DecoderType {
+ return detectorspb.DecoderType_ESCAPED_UNICODE
+}
+
func (d *EscapedUnicode) FromChunk(chunk *sources.Chunk) *DecodableChunk {
if chunk == nil || len(chunk.Data) == 0 {
return nil
@@ -94,10 +98,6 @@ func decodeCodePoint(input []byte) []byte {
return input
}
-func (d *EscapedUnicode) Type() detectorspb.DecoderType {
- return detectorspb.DecoderType_ESCAPED_UNICODE
-}
-
func decodeEscaped(input []byte) []byte {
// Find all Unicode escape sequences in the input byte slice
indices := escapePat.FindAllSubmatchIndex(input, -1)
diff --git a/pkg/decoders/utf16.go b/pkg/decoders/utf16.go
index 7f0616d25..5949196e4 100644
--- a/pkg/decoders/utf16.go
+++ b/pkg/decoders/utf16.go
@@ -11,6 +11,10 @@ import (
type UTF16 struct{}
+func (d *UTF16) Type() detectorspb.DecoderType {
+ return detectorspb.DecoderType_UTF16
+}
+
func (d *UTF16) FromChunk(chunk *sources.Chunk) *DecodableChunk {
if chunk == nil || len(chunk.Data) == 0 {
return nil
@@ -28,10 +32,6 @@ func (d *UTF16) FromChunk(chunk *sources.Chunk) *DecodableChunk {
return nil
}
-func (d *UTF16) Type() detectorspb.DecoderType {
- return detectorspb.DecoderType_UTF16
-}
-
// utf16ToUTF8 converts a byte slice containing UTF-16 encoded data to a UTF-8 encoded byte slice.
func utf16ToUTF8(b []byte) ([]byte, error) {
var bufBE, bufLE bytes.Buffer
diff --git a/pkg/decoders/utf8.go b/pkg/decoders/utf8.go
index 6672aade3..49cfea451 100644
--- a/pkg/decoders/utf8.go
+++ b/pkg/decoders/utf8.go
@@ -10,6 +10,10 @@ import (
type UTF8 struct{}
+func (d *UTF8) Type() detectorspb.DecoderType {
+ return detectorspb.DecoderType_PLAIN
+}
+
func (d *UTF8) FromChunk(chunk *sources.Chunk) *DecodableChunk {
if chunk == nil || len(chunk.Data) == 0 {
return nil
@@ -25,10 +29,6 @@ func (d *UTF8) FromChunk(chunk *sources.Chunk) *DecodableChunk {
return decodableChunk
}
-func (d *UTF8) Type() detectorspb.DecoderType {
- return detectorspb.DecoderType_PLAIN
-}
-
// extractSubstrings performs similarly to the strings binutil,
// extacting contigous portions of printable characters that we care
// about from some bytes
diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go
index 909dfa9fd..d2ca05a88 100644
--- a/pkg/engine/engine.go
+++ b/pkg/engine/engine.go
@@ -771,7 +771,7 @@ func (e *Engine) scannerWorker(ctx context.Context) {
decodeLatency.WithLabelValues(decoder.Type().String(), chunk.SourceName).Observe(float64(decodeTime))
if decoded == nil {
- ctx.Logger().V(4).Info("no decoder found for chunk", "chunk", chunk)
+ ctx.Logger().V(4).Info("decoder not applicable for chunk", "decoder", decoder.Type().String(), "chunk", chunk)
continue
}
@@ -797,7 +797,6 @@ func (e *Engine) scannerWorker(ctx context.Context) {
wgDoneFn: wgDetect.Done,
}
}
- continue
}
dataSize := float64(len(chunk.Data))