Skip to content

Decompress UPX packed binaries to extract golang build info (ELF formatted binaries with lzma method only)#4480

Merged
wagoodman merged 2 commits intomainfrom
upx-support-golang-binary
Dec 22, 2025
Merged

Decompress UPX packed binaries to extract golang build info (ELF formatted binaries with lzma method only)#4480
wagoodman merged 2 commits intomainfrom
upx-support-golang-binary

Conversation

@wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Dec 16, 2025

This PR enhances the go binary cataloger to be able to decompress LMZA payloads from ELF formatted binaries that have been packed by UPX (a known practice to make the distributed binary size smaller).

This illustrates the main issue we're trying to overcome:

# a file with a hello world example...
$ GOOS=linux GOARCH=amd64 go build -o /tmp/app main.go

$ syft -q /tmp/app -o json | jq '.artifacts | length' 
262

$ upx --best --lzma --exact /tmp/app
...
        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  93028902 ->  37142612   39.93%   linux/amd64   syft

$ syft -q /tmp/app -o json | jq '.artifacts | length'
0

$ go version -m /tmp/app    
/tmp/app: could not read Go build info from /tmp/app: not a Go executable

$ /tmp/app
hello!

What we want is for syft to be able to still catalog 262 packages from the final UPX packed binary (today we get nothing).

In the future we can expand this to be applied in other areas of syft:

  • update the file executable cataloger to detect UPX features and raise up basic info (e.g. UPX packaged, LZMA method, etc...)
  • update all other binary-based package catalogers (e.g. rust audit binary, .net binary, etc) to also be UPX aware and be able to unpack them
  • expand support for binary formats (PE / macho) and architectures

Type of change

  • New feature (non-breaking change which adds functionality)

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

@wagoodman wagoodman added this to OSS Dec 16, 2025
@wagoodman wagoodman moved this to Stalled in OSS Dec 16, 2025
@wagoodman wagoodman assigned wagoodman and unassigned wagoodman Dec 16, 2025
@wagoodman wagoodman removed this from OSS Dec 16, 2025
@wagoodman wagoodman force-pushed the upx-support-golang-binary branch from bff5d5b to 64455d7 Compare December 19, 2025 22:49
@wagoodman wagoodman marked this pull request as ready for review December 19, 2025 22:49
@wagoodman wagoodman requested a review from a team December 19, 2025 22:51
@wagoodman wagoodman changed the title Decompress UPX packed binaries to extract golang build info Decompress UPX packed binaries to extract golang build info (ELF formatted binaries with lzma method only) Dec 19, 2025
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman force-pushed the upx-support-golang-binary branch from 64455d7 to 38982a7 Compare December 19, 2025 22:56
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.

LGTM

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman enabled auto-merge (squash) December 22, 2025 14:03
@wagoodman wagoodman merged commit 0ea920b into main Dec 22, 2025
12 checks passed
@wagoodman wagoodman deleted the upx-support-golang-binary branch December 22, 2025 14:17
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.

Support reading lzma compressed .go.buildinfo sections with upx

2 participants