Skip to content

Commit

Permalink
Merge branch 'main' into update-entrypoint-script
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Jan 11, 2023
2 parents 60b9d28 + 430d5c7 commit 6d2dc5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ runs:
- git
- file://${{ inputs.path }}
- --since-commit
- ${{ inputs.base.default }}
- ${{ inputs.base }}
- --branch
- ${{ inputs.head }}
- --fail
Expand Down
25 changes: 17 additions & 8 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/sirupsen/logrus"
"google.golang.org/protobuf/proto"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
Expand Down Expand Up @@ -181,7 +182,6 @@ func (e *Engine) detectorWorker(ctx context.Context) {
for originalChunk := range e.chunks {
for chunk := range sources.Chunker(originalChunk) {
atomic.AddUint64(&e.bytesScanned, uint64(len(chunk.Data)))
fragStart, mdLine := FragmentFirstLine(chunk)
for _, decoder := range e.decoders {
var decoderType detectorspb.DecoderType
switch decoder.(type) {
Expand Down Expand Up @@ -230,9 +230,19 @@ func (e *Engine) detectorWorker(ctx context.Context) {
results = detectors.CleanResults(results)
}
for _, result := range results {
SetResultLineNumber(chunk, &result, fragStart, mdLine)
resultChunk := chunk
if SupportsLineNumbers(chunk.SourceType) {
copyChunk := *chunk
copyMetaDataClone := proto.Clone(chunk.SourceMetadata)
if copyMetaData, ok := copyMetaDataClone.(*source_metadatapb.MetaData); ok {
copyChunk.SourceMetadata = copyMetaData
}
fragStart, mdLine := FragmentFirstLine(&copyChunk)
SetResultLineNumber(&copyChunk, &result, fragStart, mdLine)
resultChunk = &copyChunk
}
result.DecoderType = decoderType
e.results <- detectors.CopyMetadata(chunk, result)
e.results <- detectors.CopyMetadata(resultChunk, result)

}
if len(results) > 0 {
Expand Down Expand Up @@ -271,7 +281,8 @@ func gitSources() []sourcespb.SourceType {
}
}

func isGitSource(sourceType sourcespb.SourceType) bool {
// SupportsLineNumbers determines if a line number can be found for a source type.
func SupportsLineNumbers(sourceType sourcespb.SourceType) bool {
for _, i := range gitSources() {
if i == sourceType {
return true
Expand Down Expand Up @@ -314,8 +325,6 @@ func FragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {

// SetResultLineNumber sets the line number in the provided result.
func SetResultLineNumber(chunk *sources.Chunk, result *detectors.Result, fragStart int64, mdLine *int64) {
if isGitSource(chunk.SourceType) {
offset := FragmentLineOffset(chunk, result)
*mdLine = fragStart + offset
}
offset := FragmentLineOffset(chunk, result)
*mdLine = fragStart + offset
}

0 comments on commit 6d2dc5e

Please sign in to comment.