Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pad artifact IDs #1882

Merged
merged 1 commit into from
Jun 16, 2023
Merged

Pad artifact IDs #1882

merged 1 commit into from
Jun 16, 2023

Conversation

willmurphyscode
Copy link
Contributor

Otherwise the hash can sometimes be short if it results in a low uint64.

This seems to be the cause of this failure: https://github.com/anchore/sbom-action/actions/runs/5270697648/jobs/9530548662?pr=418#step:6:2913

We think that padding these makes sense. Once syft hits 1.0, we'd like them to be stable, so if we want to introduce padding we want to do it while we're pre 1.0.

This was discovered while working on anchore/sbom-action#419, because it caused snapshot failures on anchore/sbom-action#418

There doesn't seem to be a great way to get a unit test around this format string, and I doubt it will ever change once committed, so performed a small experiment (in addition to updating the snapshot test) to prove this does what we want. Playground at https://go.dev/play/p/fF7C7KS0kVh, code below in case those links are short lived:

package main

import (
	"fmt"
	"math"
)

func main() {
	var x uint64 = 17
	fmt.Printf("Without padding: %x\n", x)
	fmt.Printf("With padding: %016x\n", x)
	fmt.Printf("Correct length: %d (expect 16)\n", len(fmt.Sprintf("%016x", x)))
	fmt.Println("Checking maximums")
	max := uint64(math.MaxUint64) // otherwise somehow is an int and overflows
	fmt.Printf("math.MaxUint64 in hex, same regardless of padding: %x : %016x\n", max, max)
}

which prints

Without padding: 11
With padding: 0000000000000011
Correct length: 16 (expect 16)
Checking maximums
math.MaxUint64 in hex, same regardless of padding: ffffffffffffffff : ffffffffffffffff

Otherwise the hash can sometimes be short if it results in a low uint64.

Signed-off-by: Will Murphy <will.murphy@anchore.com>
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@github-actions
Copy link

Benchmark Test Results

Benchmark results from the latest changes vs base branch
goos: linux%0Agoarch: amd64%0Apkg: github.com/anchore/syft/test/integration%0Acpu: Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz%0A                                                          │ ./.tmp/benchmark-1c9dd5e.txt │%0A                                                          │            sec/op            │%0AImagePackageCatalogers/alpmdb-cataloger-2                                   12.69m ±  2%25%0AImagePackageCatalogers/apkdb-cataloger-2                                    760.9µ ±  2%25%0AImagePackageCatalogers/binary-cataloger-2                                   214.8µ ±  1%25%0AImagePackageCatalogers/dpkgdb-cataloger-2                                   631.5µ ±  2%25%0AImagePackageCatalogers/dotnet-deps-cataloger-2                              1.295m ±  1%25%0AImagePackageCatalogers/go-module-binary-cataloger-2                         100.7µ ±  2%25%0AImagePackageCatalogers/java-cataloger-2                                     13.76m ±  1%25%0AImagePackageCatalogers/graalvm-native-image-cataloger-2                     98.36µ ±  2%25%0AImagePackageCatalogers/javascript-package-cataloger-2                       437.2µ ±  1%25%0AImagePackageCatalogers/nix-store-cataloger-2                                294.2µ ±  2%25%0AImagePackageCatalogers/php-composer-installed-cataloger-2                   838.4µ ± 20%25%0AImagePackageCatalogers/portage-cataloger-2                                  502.7µ ±  3%25%0AImagePackageCatalogers/python-package-cataloger-2                           3.421m ±  2%25%0AImagePackageCatalogers/r-package-cataloger-2                                223.3µ ±  2%25%0AImagePackageCatalogers/rpm-db-cataloger-2                                   568.5µ ±  1%25%0AImagePackageCatalogers/ruby-gemspec-cataloger-2                             957.6µ ±  1%25%0AImagePackageCatalogers/sbom-cataloger-2                                     123.1µ ±  2%25%0Ageomean                                                                     648.9µ%0A%0A                                                          │ ./.tmp/benchmark-1c9dd5e.txt │%0A                                                          │             B/op             │%0AImagePackageCatalogers/alpmdb-cataloger-2                                   5.127Mi ± 0%25%0AImagePackageCatalogers/apkdb-cataloger-2                                    205.1Ki ± 0%25%0AImagePackageCatalogers/binary-cataloger-2                                   30.18Ki ± 0%25%0AImagePackageCatalogers/dpkgdb-cataloger-2                                   169.0Ki ± 0%25%0AImagePackageCatalogers/dotnet-deps-cataloger-2                              405.5Ki ± 0%25%0AImagePackageCatalogers/go-module-binary-cataloger-2                         9.906Ki ± 0%25%0AImagePackageCatalogers/java-cataloger-2                                     2.825Mi ± 0%25%0AImagePackageCatalogers/graalvm-native-image-cataloger-2                     8.594Ki ± 0%25%0AImagePackageCatalogers/javascript-package-cataloger-2                       100.9Ki ± 0%25%0AImagePackageCatalogers/nix-store-cataloger-2                                49.14Ki ± 0%25%0AImagePackageCatalogers/php-composer-installed-cataloger-2                   186.6Ki ± 0%25%0AImagePackageCatalogers/portage-cataloger-2                                  120.0Ki ± 0%25%0AImagePackageCatalogers/python-package-cataloger-2                           1.003Mi ± 0%25%0AImagePackageCatalogers/r-package-cataloger-2                                53.29Ki ± 0%25%0AImagePackageCatalogers/rpm-db-cataloger-2                                   180.9Ki ± 0%25%0AImagePackageCatalogers/ruby-gemspec-cataloger-2                             144.0Ki ± 0%25%0AImagePackageCatalogers/sbom-cataloger-2                                     14.20Ki ± 0%25%0Ageomean                                                                     132.7Ki%0A%0A                                                          │ ./.tmp/benchmark-1c9dd5e.txt │%0A                                                          │          allocs/op           │%0AImagePackageCatalogers/alpmdb-cataloger-2                                    87.75k ± 0%25%0AImagePackageCatalogers/apkdb-cataloger-2                                     4.182k ± 0%25%0AImagePackageCatalogers/binary-cataloger-2                                     830.0 ± 0%25%0AImagePackageCatalogers/dpkgdb-cataloger-2                                    3.000k ± 0%25%0AImagePackageCatalogers/dotnet-deps-cataloger-2                               6.338k ± 0%25%0AImagePackageCatalogers/go-module-binary-cataloger-2                           281.0 ± 0%25%0AImagePackageCatalogers/java-cataloger-2                                      39.88k ± 0%25%0AImagePackageCatalogers/graalvm-native-image-cataloger-2                       228.0 ± 0%25%0AImagePackageCatalogers/javascript-package-cataloger-2                        1.404k ± 0%25%0AImagePackageCatalogers/nix-store-cataloger-2                                  895.0 ± 0%25%0AImagePackageCatalogers/php-composer-installed-cataloger-2                    4.079k ± 0%25%0AImagePackageCatalogers/portage-cataloger-2                                   2.269k ± 0%25%0AImagePackageCatalogers/python-package-cataloger-2                            16.44k ± 0%25%0AImagePackageCatalogers/r-package-cataloger-2                                  929.0 ± 0%25%0AImagePackageCatalogers/rpm-db-cataloger-2                                    3.989k ± 0%25%0AImagePackageCatalogers/ruby-gemspec-cataloger-2                              2.447k ± 0%25%0AImagePackageCatalogers/sbom-cataloger-2                                       394.0 ± 0%25%0Ageomean                                                                      2.583k

@willmurphyscode willmurphyscode merged commit e2ed89f into main Jun 16, 2023
@willmurphyscode willmurphyscode deleted the fix-pad-artifact-id branch June 16, 2023 17:26
@willmurphyscode willmurphyscode added breaking-change Change is not backwards compatible bug Something isn't working and removed bug Something isn't working labels Jun 16, 2023
GijsCalis pushed a commit to GijsCalis/syft that referenced this pull request Feb 19, 2024
Otherwise the hash can sometimes be short if it results in a low uint64.

Signed-off-by: Will Murphy <will.murphy@anchore.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Change is not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants