@@ -5,6 +5,7 @@ package programkind
55
66import (
77 "bytes"
8+ "context"
89 "errors"
910 "fmt"
1011 "io/fs"
@@ -123,11 +124,11 @@ const headerSize int = 512
123124
124125// IsSupportedArchive returns whether a path can be processed by our archive extractor.
125126// UPX files are an edge case since they may or may not even have an extension that can be referenced.
126- func IsSupportedArchive (path string ) bool {
127+ func IsSupportedArchive (ctx context. Context , path string ) bool {
127128 if _ , isValidArchive := ArchiveMap [GetExt (path )]; isValidArchive {
128129 return true
129130 }
130- if ft , err := File (path ); err == nil && ft != nil {
131+ if ft , err := File (ctx , path ); err == nil && ft != nil {
131132 if ft .MIME == "application/x-upx" {
132133 return true
133134 }
@@ -179,7 +180,7 @@ func UPXInstalled() error {
179180}
180181
181182// IsValidUPX checks whether a suspected UPX-compressed file can be decompressed with UPX.
182- func IsValidUPX (header []byte , path string ) (bool , error ) {
183+ func IsValidUPX (ctx context. Context , header []byte , path string ) (bool , error ) {
183184 if ! bytes .Contains (header , []byte ("UPX!" )) {
184185 return false , nil
185186 }
@@ -188,7 +189,7 @@ func IsValidUPX(header []byte, path string) (bool, error) {
188189 return false , err
189190 }
190191
191- cmd := exec .Command ( "upx" , "-l" , "-f" , path )
192+ cmd := exec .CommandContext ( ctx , "upx" , "-l" , "-f" , path )
192193 output , err := cmd .CombinedOutput ()
193194
194195 if err != nil && (bytes .Contains (output , []byte ("NotPackedException" )) ||
@@ -240,7 +241,7 @@ func makeFileType(path string, ext string, mime string) *FileType {
240241}
241242
242243// File detects what kind of program this file might be.
243- func File (path string ) (* FileType , error ) {
244+ func File (ctx context. Context , path string ) (* FileType , error ) {
244245 // Follow symlinks and return cleanly if the target does not exist
245246 _ , err := filepath .EvalSymlinks (path )
246247 if os .IsNotExist (err ) {
@@ -292,7 +293,7 @@ func File(path string) (*FileType, error) {
292293 }
293294
294295 // final strategy: DIY matching where mimetype is too strict.
295- if isUPX , err := IsValidUPX (hdr , path ); err == nil && isUPX {
296+ if isUPX , err := IsValidUPX (ctx , hdr , path ); err == nil && isUPX {
296297 return Path (".upx" ), nil
297298 }
298299
0 commit comments