mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
chore: lint-fix
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
parent
6ceef5fe4a
commit
f92b7d2fc9
@ -3,6 +3,7 @@ package task
|
|||||||
import (
|
import (
|
||||||
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
|
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
|
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
|
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/arch"
|
"github.com/anchore/syft/syft/pkg/cataloger/arch"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/binary"
|
"github.com/anchore/syft/syft/pkg/cataloger/binary"
|
||||||
@ -37,7 +38,6 @@ import (
|
|||||||
"github.com/anchore/syft/syft/pkg/cataloger/swipl"
|
"github.com/anchore/syft/syft/pkg/cataloger/swipl"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/terraform"
|
"github.com/anchore/syft/syft/pkg/cataloger/terraform"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
|
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
|
||||||
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@ -40,9 +40,10 @@ func EncodeComponent(p pkg.Package, supplier string, locationSorter func(a, b fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentType := cyclonedx.ComponentTypeLibrary
|
componentType := cyclonedx.ComponentTypeLibrary
|
||||||
if p.Type == pkg.BinaryPkg {
|
switch p.Type {
|
||||||
|
case pkg.BinaryPkg:
|
||||||
componentType = cyclonedx.ComponentTypeApplication
|
componentType = cyclonedx.ComponentTypeApplication
|
||||||
} else if p.Type == pkg.ModelPkg {
|
case pkg.ModelPkg:
|
||||||
componentType = cyclonedx.ComponentTypeMachineLearningModel
|
componentType = cyclonedx.ComponentTypeMachineLearningModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,7 +41,9 @@ const (
|
|||||||
ggufTypeArray = 12
|
ggufTypeArray = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
// parseGGUFHeader parses the header of a GGUF file from raw bytes and extracts metadata
|
const unkownGGUFData = "unknown"
|
||||||
|
|
||||||
|
//nolint:funlen
|
||||||
func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error) {
|
func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error) {
|
||||||
reader := bytes.NewReader(data)
|
reader := bytes.NewReader(data)
|
||||||
// Read magic number
|
// Read magic number
|
||||||
@ -83,7 +85,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse metadata key-value pairs
|
// Parse metadata key-value pairs
|
||||||
kvMap := make(map[string]interface{})
|
kvMap := make(map[string]any)
|
||||||
truncated := false
|
truncated := false
|
||||||
|
|
||||||
for i := uint64(0); i < kvCount; i++ {
|
for i := uint64(0); i < kvCount; i++ {
|
||||||
@ -133,7 +135,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
metadata.ModelVersion = version
|
metadata.ModelVersion = version
|
||||||
delete(kvMap, "general.version")
|
delete(kvMap, "general.version")
|
||||||
} else {
|
} else {
|
||||||
metadata.ModelVersion = "unknown"
|
metadata.ModelVersion = unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract parameters count if present
|
// Extract parameters count if present
|
||||||
@ -151,7 +153,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
|
|||||||
metadata.Quantization = inferQuantizationFromFilename(location)
|
metadata.Quantization = inferQuantizationFromFilename(location)
|
||||||
// Note: we keep general.quantized_by in Header since it's not directly mapped to a field
|
// Note: we keep general.quantized_by in Header since it's not directly mapped to a field
|
||||||
} else {
|
} else {
|
||||||
metadata.Quantization = "unknown"
|
metadata.Quantization = unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute hash of metadata for stable identifier
|
// Compute hash of metadata for stable identifier
|
||||||
@ -194,8 +196,8 @@ func readKVPair(reader io.Reader) (string, interface{}, error) {
|
|||||||
return key, value, nil
|
return key, value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readValue reads a value based on its type
|
//nolint:funlen
|
||||||
func readValue(reader io.Reader, valueType uint32) (interface{}, error) {
|
func readValue(reader io.Reader, valueType uint32) (any, error) {
|
||||||
switch valueType {
|
switch valueType {
|
||||||
case ggufTypeUint8:
|
case ggufTypeUint8:
|
||||||
var v uint8
|
var v uint8
|
||||||
@ -308,7 +310,7 @@ func inferQuantizationFromFilename(filename string) string {
|
|||||||
if match := quantPattern.FindString(filename); match != "" {
|
if match := quantPattern.FindString(filename); match != "" {
|
||||||
return match
|
return match
|
||||||
}
|
}
|
||||||
return "unknown"
|
return unkownGGUFData
|
||||||
}
|
}
|
||||||
|
|
||||||
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier
|
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier
|
||||||
@ -341,4 +343,3 @@ func computeMetadataHash(metadata *pkg.GGUFFileMetadata) string {
|
|||||||
hash := sha256.Sum256(jsonBytes)
|
hash := sha256.Sum256(jsonBytes)
|
||||||
return fmt.Sprintf("%x", hash[:8]) // Use first 8 bytes (16 hex chars)
|
return fmt.Sprintf("%x", hash[:8]) // Use first 8 bytes (16 hex chars)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
// parseGGUFModel parses a GGUF model file and returns the discovered package.
|
// parseGGUFModel parses a GGUF model file and returns the discovered package.
|
||||||
func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||||
defer internal.CloseAndLogError(reader, reader.Location.Path())
|
defer internal.CloseAndLogError(reader, reader.Path())
|
||||||
|
|
||||||
// Read header (we'll read a reasonable amount to parse the header without reading entire file)
|
// Read header (we'll read a reasonable amount to parse the header without reading entire file)
|
||||||
// GGUF headers are typically < 1MB, but we'll use a 10MB limit to be safe
|
// GGUF headers are typically < 1MB, but we'll use a 10MB limit to be safe
|
||||||
@ -39,7 +39,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
}
|
}
|
||||||
// Stop if we've read enough for a reasonable header
|
// Stop if we've read enough for a reasonable header
|
||||||
if len(headerData) > maxHeaderSize {
|
if len(headerData) > maxHeaderSize {
|
||||||
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Location.Path())
|
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Path())
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse the GGUF header
|
// Parse the GGUF header
|
||||||
metadata, err := parseGGUFHeader(headerData, reader.Location.Path())
|
metadata, err := parseGGUFHeader(headerData, reader.Path())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to parse GGUF file: %w", err)
|
return nil, nil, fmt.Errorf("failed to parse GGUF file: %w", err)
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
// Create package from metadata
|
// Create package from metadata
|
||||||
p := newGGUFPackage(
|
p := newGGUFPackage(
|
||||||
metadata,
|
metadata,
|
||||||
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
||||||
)
|
)
|
||||||
|
|
||||||
return []pkg.Package{p}, nil, unknown.IfEmptyf([]pkg.Package{p}, "unable to parse GGUF file")
|
return []pkg.Package{p}, nil, unknown.IfEmptyf([]pkg.Package{p}, "unable to parse GGUF file")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user