Skip to content

fix(rpm): keep the epoch when parsing RPM manifest packages - #5201

Merged
spiffcs merged 2 commits into
anchore:mainfrom
sueun-dev:fix-rpm-manifest-epoch
Aug 21, 2026
Merged

fix(rpm): keep the epoch when parsing RPM manifest packages#5201
spiffcs merged 2 commits into
anchore:mainfrom
sueun-dev:fix-rpm-manifest-epoch

Conversation

@sueun-dev

Copy link
Copy Markdown
Contributor

Description

newMetadataFromManifestLine parses the RPM manifest used in Mariner / Azure Linux distroless containers. It decoded the epoch and size into the same local variable, set epoch = &converted, then reassigned converted to the size field:

converted, err := strconv.Atoi(parts[8]) // EPOCHNUM
...
epoch = &converted
converted, err = strconv.Atoi(parts[6])  // SIZE

For a manifest line with EPOCH 2 and SIZE 45000, Syft produced version 45000:9.0-1.cm2 and PURL pkg:rpm/vim@9.0-1.cm2?arch=x86_64&epoch=45000&upstream=vim-9.0-1.cm2.src.rpm instead of keeping epoch 2.

This binds the epoch to its own variable so decoding the size cannot overwrite it. I also added a container-manifest-2 fixture line with a real epoch; the existing lines all used EPOCH (none), so this branch was not covered.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have added unit tests that cover changed behavior
  • I have tested my code in common scenarios and confirmed there are no regressions
  • I have added comments to my code, particularly in hard-to-understand sections

Issue references

None.

Testing

With only the code change reverted and the new test kept, go test ./syft/pkg/cataloger/redhat -run TestParseRpmManifest -count=1 -v fails with Epoch -: 2 +: 45000, Version -: 2:9.0-1.cm2 +: 45000:9.0-1.cm2, and PURL using epoch=45000.

With the fix:

go test ./syft/pkg/cataloger/redhat -run TestParseRpmManifest -count=1 -v
go build ./...
golangci-lint run ./syft/pkg/cataloger/redhat/...
gofmt -l syft/pkg/cataloger/redhat/package.go syft/pkg/cataloger/redhat/parse_rpm_manifest_test.go
git diff --check origin/main...HEAD

TestParseRpmFiles still fails here on a clean main because testdata/rpms is not present in a plain checkout, and the broader redhat cataloger tests need a local Docker daemon. Those are unrelated to this change. go vet ./syft/pkg/cataloger/redhat also reports the same pre-existing test-file warnings on clean origin/main.

sueun-dev and others added 2 commits August 11, 2026 13:13
newMetadataFromManifestLine decoded the epoch (EPOCHNUM) and the size into
the same converted variable and set epoch = &converted, then reassigned
converted to the size. The returned epoch pointer therefore held the size
whenever a package had a real (non-"(none)") epoch, producing a wrong
version and PURL. Epoch is highest-precedence in RPM version comparison, so
this breaks advisory matching downstream.

Bind the epoch to its own variable and add a fixture line with a non-"(none)"
epoch to cover the branch (every existing fixture line used "(none)").

Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
…size edge cases

Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>

@spiffcs spiffcs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @sueun-dev! I made a small change and updated the bug fix to use parseEpoch. TY for adding the new test and getting this up for us to review.

@spiffcs
spiffcs merged commit 93cf893 into anchore:main Aug 21, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants