Skip to content

fix(cpe): bound CPE candidate generation for pathological package metadata - #5356

Merged
wagoodman merged 2 commits into
mainfrom
fix/cpe-subselection-blowup
Sep 29, 2026
Merged

wagoodman merged 2 commits into
mainfrom
fix/cpe-subselection-blowup

Conversation

@wagoodman

Copy link
Copy Markdown
Contributor

CPE generation in FromPackageAttributes crosses every vendor candidate with every product candidate. Several inputs could inflate those counts without bound, so hostile package metadata could cost minutes and GBs:

  • a name with many -/_ separators became one vendor candidate per segment prefix, each O(name length). That's quadratic: an 8KB name took ~250s and 4.8GB.
  • java groupIDs add a vendor per dot segment, and with no artifactID a product per segment too. A 1000-segment Bundle-SymbolicName produced ~1M CPEs and 8.4GB.
  • .NET Executables have the same shape, one vendor and one product per file.
  • long names or versions are paid once per CPE in key building and regex validation (a 1MB version took ~12s).

The fix bounds things in two places:

  • generateSubSelections stops after 10 prefixes (the full name is still a candidate).
  • FromPackageAttributes skips names/versions over 512 bytes, drops candidates over 512 bytes, and keeps at most 64 vendor and 64 product candidates (shortest first, so truncation is deterministic).

Real packages produce around a dozen candidates, with names well under 100 bytes, so output for real inputs shouldn't change.

a name with thousands of `-`/`_` separators produced one vendor and product candidate per segment, and the vendor x product cross-product made CPE generation roughly cubic in time and memory (8KB name: ~250s, 4.8GB RSS). `generateSubSelections` now stops after 10 prefixes. The full name is still a candidate, so real package names are unaffected.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
…duct

the prefix cap only covered one way to inflate the vendor x product cross-product in `FromPackageAttributes`. Java groupIDs add a vendor (and, with no artifactID, a product) per dot segment, and .NET executables add one of each per file, so a 1000-segment `Bundle-SymbolicName` still produced ~1M CPEs and several GB.

- vendor and product candidates are each capped at 64 (shortest first, so truncation is deterministic)
- names, versions, and candidates over 512 bytes are skipped, since every byte is paid once per CPE in key building and regex validation

real packages produce around a dozen candidates with names well under 100 bytes, so output for real inputs is unchanged. Also corrects the earlier comment: prefixes only become vendor candidates and the cost was quadratic, not cubic.

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman added the bug Something isn't working label Sep 29, 2026
@wagoodman
wagoodman enabled auto-merge (squash) September 29, 2026 19:36
@wagoodman
wagoodman merged commit 57bd6a5 into main Sep 29, 2026
15 checks passed
@wagoodman
wagoodman deleted the fix/cpe-subselection-blowup branch September 29, 2026 20:01
spiffcs added a commit that referenced this pull request Sep 30, 2026
* main: (91 commits)
  feat: catalog CPAN distributions installed by perl clients (#5131)
  fix(binary): correct traefik version detection on big-endian arches (#5281)
  Fix hang when scanning a Java resource adapter (.rar) file (#5348)
  chore(deps): update SPDX license list (#5315)
  fix: match opensource.org license URLs across SPDX URL forms (#5361)
  Speed up unit tests in CI (#5360)
  Fix missing file hashes when running on windows system (#5341)
  Stop reading the mount table for every single-file source (#5257)
  fix: conan expat CPE (#5259)
  fix(spdx): write a name for the root package when the source has none (#5349)
  fix(python): link uv.lock dependents to the locked version they name (#5351)
  fix: suppress misleading upstream CPE for PHP extension binaries (#5102)
  fix: report scanner errors and raise the line cap in metadata parsers (#5353)
  Harden cataloger parsers against truncated input (do not panic) (#5355)
  fix(cpe): bound CPE candidate generation for pathological package metadata (#5356)
  test(golang): make the UPX fixture exercise loader padding (#5354)
  fix(golang): account for UPX's loader padding when unpacking Go binaries (#5347)
  test(snap): bound the kernel changelog bomb fixture by ratio, not a fixed 1MB (#5352)
  test(debian): bound the bomb fixture by ratio, not a fixed 1MB (#5350)
  fix(ai): handle malformed GGUF headers without panicking (#5345)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants