Skip to content

Comments

fix: improve diff determinism for UPX files and file moves in general#1265

Merged
egibs merged 2 commits intochainguard-dev:mainfrom
egibs:fix-diff-flakiness
Dec 12, 2025
Merged

fix: improve diff determinism for UPX files and file moves in general#1265
egibs merged 2 commits intochainguard-dev:mainfrom
egibs:fix-diff-flakiness

Conversation

@egibs
Copy link
Member

@egibs egibs commented Dec 12, 2025

Relates to: #1230

There was still a remaining edge case for diffing non-UPX files with a UPX file. Since we preserve the original file when decompressing a UPX file, the chosen file would sometimes be the decompressed file or the original file which would produce inconsistent results.

This PR prefers the decompressed version (i.e., the file without the .~ suffix) which matches our existing archive diffing behavior. We do want to handle UPX files better in the future but this will resolve the immediate issues.

Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
Copy link
Member

@stevebeattie stevebeattie left a comment

Choose a reason for hiding this comment

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

One question, but not a blocker for this PR. Thanks!

Comment on lines +118 to +121
// selectPrimaryFile selects a single file from a map of file reports in a deterministic way.
// e.g., when a UPX-packed file is scanned, it produces the decompressed file
// and preserves the original file (with a .~ suffix).
func selectPrimaryFile(files map[string]*malcontent.FileReport) *malcontent.FileReport {
Copy link
Member

Choose a reason for hiding this comment

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

I know we currently only use this for diff results, but is there a situation where we'd want to use this function for non-diff reports?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I can't think of an exact example right now but there could be a situation where we'd want to favor one variant of a file over another if they share the same name.

@egibs egibs merged commit 3d818a5 into chainguard-dev:main Dec 12, 2025
14 checks passed
@egibs egibs deleted the fix-diff-flakiness branch December 12, 2025 19:42
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