Skip to content

Commit

Permalink
[fixup] - skip files in the archive handler (trufflesecurity#2195)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav authored Dec 9, 2023
1 parent 2728e51 commit 331336d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/handlers/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (a *Archive) openArchive(ctx context.Context, depth int, reader io.Reader,
switch archive := format.(type) {
case archiver.Decompressor:
info := decompressorInfo{depth: depth, reader: arReader, archiveChan: archiveChan, archiver: archive}

return a.handleDecompressor(ctx, info)
case archiver.Extractor:
return archive.Extract(context.WithValue(ctx, depthKey, depth+1), reader, nil, a.extractorHandler(archiveChan))
Expand Down Expand Up @@ -142,8 +143,7 @@ func (a *Archive) handleDecompressor(ctx context.Context, info decompressorInfo)
if err != nil {
return err
}
newReader := bytes.NewReader(fileBytes)
return a.openArchive(ctx, info.depth+1, newReader, info.archiveChan)
return a.openArchive(ctx, info.depth+1, bytes.NewReader(fileBytes), info.archiveChan)
}

// IsFiletype returns true if the provided reader is an archive.
Expand Down Expand Up @@ -176,13 +176,17 @@ func (a *Archive) extractorHandler(archiveChan chan []byte) func(context.Context
if err != nil {
return err
}
if common.SkipFile(f.Name()) {
logger.V(5).Info("skipping file", "filename", f.Name())
return nil
}

fileBytes, err := a.ReadToMax(ctx, fReader)
if err != nil {
return err
}
fileContent := bytes.NewReader(fileBytes)

err = a.openArchive(ctx, depth, fileContent, archiveChan)
err = a.openArchive(ctx, depth, bytes.NewReader(fileBytes), archiveChan)
if err != nil {
return err
}
Expand Down

0 comments on commit 331336d

Please sign in to comment.