syft icon indicating copy to clipboard operation
syft copied to clipboard

Checksum is 0 for spdx files

Open coheigea opened this issue 3 years ago • 19 comments

What happened:

An SPDX json report contains a 0 value for the file checksum. It looks like it is not adding/using the path. If you give me some pointers I can take a look at a PR.

"files": [
  {
   "fileName": "/activemq-osgi-5.18.2.jar",
   "SPDXID": "SPDXRef-File-activemq-osgi-5.18.2.jar-57d3ba18b01bbbb8",
   "checksums": [
    {
     "algorithm": "SHA1",
     "checksumValue": "0000000000000000000000000000000000000000"
    }
   ],
   "licenseConcluded": "NOASSERTION",
   "copyrightText": ""
  }
 ],

What you expected to happen:

Correct file checksum, like in the packages section.

Steps to reproduce the issue:

  • wget https://repo1.maven.org/maven2/org/apache/activemq/activemq-osgi/5.18.2/activemq-osgi-5.18.2.jar
  • syft packages ./activemq-osgi-5.18.2.jar -o spdx-json > activemq.json

Anything else we need to know?:

Environment:

  • syft 0.95.0

coheigea avatar Nov 09 '23 07:11 coheigea

The latest version of Syft (0.97.1) seems to be omitting these empty checksums; following the steps above, the files section has:

 "files": [
  {  
   "id": "57d3ba18b01bbbb8",
   "location": {
    "path": "/activemq-osgi-5.18.2.jar"
   }
  }
 ],

... and when enabling SHA1 checksums:

{  
   "id": "57d3ba18b01bbbb8",
   "location": {
    "path": "/activemq-osgi-5.18.2.jar"
   },
   "metadata": {
    "mode": 644,
    "type": "RegularFile",
    "userID": 501,
    "groupID": 20,
    "mimeType": "application/jar",
    "size": 13242590
   },
   "digests": [
    {
     "algorithm": "sha1",
     "value": "3be830039fd9548f1e422fbbe0b6d47013cb9ac1"
    }
   ]
  }

Since this seems to be working as expected, I'm going to close it for now, but please do reopen if it continues to be an issue for you!

kzantow avatar Nov 27 '23 15:11 kzantow

@kzantow This is what I see with 0.97.1 activemq.json

As you can see it still has the 000 checksum

coheigea avatar Nov 27 '23 16:11 coheigea

@coheigea I apparently didn't actually follow your steps to reproduce accurately, the issue definitely exists when using the right output format; apologies!

kzantow avatar Nov 27 '23 16:11 kzantow

Any update on this issue?

yves-bischoff avatar Nov 21 '24 14:11 yves-bischoff

Any updates on that issue?

barakharyati avatar Mar 11 '25 11:03 barakharyati

This is still an issue as of 1.38.2 is there an update on this? I also tried to force SHA-256, but it seems to ignore that and continues to produce SHA-1 0000000.....

file: metadata: selection: "all" digests: - "sha256"

EarlRoth avatar Dec 11 '25 21:12 EarlRoth

By default, Syft will catalog file details and digests for files that are owned by discovered packages. You can change this behavior by using the SYFT_FILE_METADATA_SELECTION environment variable or the file.metadata.selection configuration option. The options are: all: capture all files from the search space owned-by-package: capture only files owned by packages (default) none: disable capturing any file information

Based on Wiki, I tried SYFT_FILE_METADATA_SELECTION=all and some of SHA values showed non-zero.

But lots of file still shows 00000.... I'm trying to investigate this (I think the problem is from how syft(coordinate thing) handles hardlink of files)

yureutaejin avatar Jan 07 '26 14:01 yureutaejin

I think the problem is from how syft(coordinate thing) handles hardlink of files

We see it for empty files, which are not hardlinks. For example:

# curl -SsL https://files.pythonhosted.org/packages/b9/2d/f4896b59ff21d1bf228bde2973b5c5af2debc71e11137533dd088f094846/boto3-1.40.67-py3-none-any.whl -O
# mkdir wheel
# pushd wheel
# unzip ../boto3-1.40.67-py3-none-any.whl
# popd
# syft scan dir:wheel --output spdx-json=sbom.json
# jq < sbom.json| grep -B 10 00000
},
    {
      "fileName": "boto3/resources/__init__.py",
      "SPDXID": "SPDXRef-File-boto3-resources---init--.py-a9eaa292d3d663e8",
      "fileTypes": [
        "OTHER"
      ],
      "checksums": [
        {
          "algorithm": "SHA1",
          "checksumValue": "0000000000000000000000000000000000000000"
# ls -l wheel/boto3/resources/__init__.py
# -rw-r--r--  1 user   group  0 Nov  5 19:05 wheel/boto3/resources/__init__.py

ppalucha avatar Feb 03 '26 11:02 ppalucha

Here's proposed fix: https://github.com/anchore/syft/pull/4620

ppalucha avatar Feb 13 '26 11:02 ppalucha

Just wondering why this item was closed, as the applied fix only appears to address empty files, while the reported issue affects all files.

I am still seeing this issue in 1.45.0. I should note that this is for a .NET project, and I generate the SBOM on a windows-latest image. I have not tested any other operating systems.

As a result, I had to switch to the Microsoft SBOM Tool to generate the SBOM. I really like the Syft’s approach of resolving package information from built binaries rather than source code, but due to this issue I am currently unable to use it.

naurisivanans avatar Jun 05 '26 23:06 naurisivanans

@naurisivanans are you seeing checksums being filled with zeroes for files or just that some files are omitted? If you provide a way to reproduce the behavior you're seeing maybe it would help to understand; probably best to open a new issue at this point. Keep in mind that Syft has different options for hashing files and including checksums -- e.g. by default only files where packages were found are hashed.

kzantow avatar Jun 05 '26 23:06 kzantow

@kzantow thanks for a quick reply. Every single file included in the SBOM has only SHA1 checksum with zeros. I do see packages section populated though. I will create a dummy dotnet CLI project to illustrate the issue. As it is exactly the same issue as originally reported, please advise if you want me to create a new issue or attach the test project to this issue.

naurisivanans avatar Jun 05 '26 23:06 naurisivanans

Either way, if it's exactly the same issue we can reopen this, just please provide a way to exhibit the issues; thanks!

kzantow avatar Jun 05 '26 23:06 kzantow

Attached a zip file with empty .NET 10 "Hello World!" project with one NuGet package dependency - Newtonsoft.Json.

Attached project already have SOMB file in .\bin\Publish\sbon.json generated on my machine. Newtonsoft.Json package info was populated correctly, however all files have only SHA1 checkusums with all zeros.

To reproduce the issue:

  1. Unzip the project.
  2. Navigate to .\bin\Publish
  3. Run syft . -c syft.yaml -o spdx-json > sbom.json

Please let me know if you need any additional information.

DummyApp.zip

naurisivanans avatar Jun 06 '26 00:06 naurisivanans

@naurisivanans your syft.yaml has disabled SHA1 checksums (only SHA256 are enabled). SHA1 checksums are required in certain fields in SPDX, but since you've disabled this they are not available. Syft adheres to the spec by filling with zeroes. You need to enable sha1 in your configuration.

kzantow avatar Jun 07 '26 17:06 kzantow

@kzantow I tried following:

  1. Both - sha1 and sha256 in config file
  2. Just sha1 in config file
  3. Just sha256 in config file
  4. Same 3 combinations above with SYFT_FILE_METADATA_DIGESTS env var.

All of these cases always generate file with ONLY SHA1 checksum with value as all zeroes.

Did you try to generate the file on Windows machine with my attached test project and adjust config file to included both sha1 and sha256 digest and it produced SBOM with valid hashes?

naurisivanans avatar Jun 08 '26 18:06 naurisivanans

@naurisivanans by default Syft generates SHA1 and SHA256. If you run without a config file at all, it works as expected with nonzero hashes. If you modify the configuration file to include sha1, it works as expected:

 % cat syft.yaml 
format:
  pretty: true
file:
  metadata:
    selection: all
    digests:
      - sha1
      - sha256
source:
  name: "DummyApp"
  version: "1.0.0"
  supplier: "Dummy App Inc"

% syft -c syft.yaml .
...
{
  "spdxVersion": "SPDX-2.3",
  "dataLicense": "CC0-1.0",
  "SPDXID": "SPDXRef-DOCUMENT",
  "name": "DummyApp",
  "documentNamespace": "https://anchore.com/syft/dir/DummyApp-188ab459-055f-4fc1-80f1-3e6621abd9db",
  "creationInfo": {
    "licenseListVersion": "3.28",
    "creators": [
...
    {
      "fileName": "",
      "SPDXID": "SPDXRef-File--5567c94c988a1a09",
      "fileTypes": [
        "OTHER"
      ],
      "checksums": [
        {
          "algorithm": "SHA1",
          "checksumValue": "0000000000000000000000000000000000000000"
        }
      ],
      "licenseConcluded": "NOASSERTION",
      "licenseInfoInFiles": [
        "NOASSERTION"
      ],
      "copyrightText": "NOASSERTION"
    },
    {
      "fileName": "DummyApp.deps.json",
      "SPDXID": "SPDXRef-File-DummyApp.deps.json-1a1b80a67f10b564",
      "fileTypes": [
        "APPLICATION"
      ],
      "checksums": [
        {
          "algorithm": "SHA1",
          "checksumValue": "0e3ab165dbdd5d2c1d6f0745aaa87178a06023f8"
        },
        {
          "algorithm": "SHA256",
          "checksumValue": "0a376808b8759645b28aca3d436b9d94b86275f18dec208793287e58bd4c3ce2"
        }
      ],
      "licenseConcluded": "NOASSERTION",
      "licenseInfoInFiles": [
        "NOASSERTION"
      ],
      "copyrightText": "NOASSERTION"
    },

You will see SHA1 values for files that were hashed. Since it was a directory scan, the directory is included weirdly as a file with zeroes, since it was not hashed.

kzantow avatar Jun 08 '26 19:06 kzantow

Not using config file was actually first thing we tried. Same results though, just SHA1 and all zero checksums. I have actually never seen SHA256 produced in the generated file.

I asked a colleague of mine to test it on their machine as well and same results. No config file and just plain - syft -o spdx-json > sbom.json inside the Publish folder of the attached DummyApp. Tried on Win10 and Win11 and we see only SHA1 checksums with zeros only.

Just to make sure - are you generating your file on a Windows system? I do see bash commands in your last comment so I would assume the file was generated on another OS. Could it be OS specific bug?

Attaching both sboms generated on win11 and win10 machines. sbomw10.json sbom.json

naurisivanans avatar Jun 08 '26 19:06 naurisivanans

I've been using macOS, we have had some issues affecting only Windows. Please open another issue since this seems to be a slightly different problem than what was originally reported and we can stop pinging the original reporter here.

kzantow avatar Jun 08 '26 22:06 kzantow