mirror of
https://github.com/anchore/syft.git
synced 2026-08-19 16:48:27 +02:00
fix(apk): allow large installed db fields (#5100)
Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com> Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
This commit is contained in:
parent
12b8ba47fb
commit
2dcf5163b8
@ -32,12 +32,15 @@ type parsedData struct {
|
|||||||
pkg.ApkDBEntry
|
pkg.ApkDBEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const maxApkDBFieldSize = 10 * 1024 * 1024
|
||||||
|
|
||||||
// parseApkDB parses packages from a given APK "installed" flat-file DB. For more
|
// parseApkDB parses packages from a given APK "installed" flat-file DB. For more
|
||||||
// information on specific fields, see https://wiki.alpinelinux.org/wiki/Apk_spec.
|
// information on specific fields, see https://wiki.alpinelinux.org/wiki/Apk_spec.
|
||||||
//
|
//
|
||||||
//nolint:funlen
|
//nolint:funlen
|
||||||
func parseApkDB(ctx context.Context, resolver file.Resolver, env *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
func parseApkDB(ctx context.Context, resolver file.Resolver, env *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||||
scanner := bufio.NewScanner(reader)
|
scanner := bufio.NewScanner(reader)
|
||||||
|
scanner.Buffer(nil, maxApkDBFieldSize)
|
||||||
|
|
||||||
var errs error
|
var errs error
|
||||||
var apks []parsedData
|
var apks []parsedData
|
||||||
|
|||||||
@ -719,6 +719,25 @@ func Test_processChecksum(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseApkDBAllowsLargeFieldValues(t *testing.T) {
|
||||||
|
contents := strings.Join([]string{
|
||||||
|
"P:large-description",
|
||||||
|
"V:1.0-r0",
|
||||||
|
"A:x86_64",
|
||||||
|
"S:1",
|
||||||
|
"I:1",
|
||||||
|
"T:" + strings.Repeat("a", 70*1024),
|
||||||
|
"",
|
||||||
|
}, "\n")
|
||||||
|
reader := file.NewLocationReadCloser(file.NewLocation("large-installed-db"), io.NopCloser(strings.NewReader(contents)))
|
||||||
|
|
||||||
|
pkgs, _, err := parseApkDB(context.Background(), nil, new(generic.Environment), reader)
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, pkgs, 1)
|
||||||
|
assert.Equal(t, "large-description", pkgs[0].Name)
|
||||||
|
}
|
||||||
|
|
||||||
func Test_parseApkDB_expectedPkgNames(t *testing.T) {
|
func Test_parseApkDB_expectedPkgNames(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
fixture string
|
fixture string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user