Skip to content

fix(python): read metadata headers past the first three lines - #6175

Closed
saswatdutta1310 wants to merge 1 commit into
ossf:mainfrom
saswatdutta1310:bot/cvebin-metadata-header-block-dco
Closed

saswatdutta1310 wants to merge 1 commit into
ossf:mainfrom
saswatdutta1310:bot/cvebin-metadata-header-block-dco

Conversation

@saswatdutta1310

Copy link
Copy Markdown

Supersedes #6174 (closed to re-sign the commit for DCO).

Summary

PythonParser.run_checker() truncated METADATA / PKG-INFO to the first three lines before looking for Name: and Version:. Core Metadata is RFC 822 style, so Version: may legitimately appear later in the header block; those files were silently skipped. The parser now reads the header block up to the first blank line.

Closes #6162

Reproduction

With the new test applied to unmodified HEAD (7bd8e09):

python -m pytest test/test_python.py -q -k reads_version_later_in_header

Observed (exit 1):

E       AssertionError: assert [] == [('selenium', '4.22.0')]
FAILED test/test_python.py::test_python_parser_reads_version_later_in_header

The file has Name: selenium on line 2 and Version: 4.22.0 on line 6; the old lines.splitlines()[:3] cut the version off, so the parser yielded no ScanInfo.

Root cause

cve_bin_tool/parsers/python.py:331 used a fixed three-line window. RFC 822 header fields have no fixed ordering, so a valid Version: field beyond line 3 was discarded before the ^Version: (.+)$ search.

Fix

Split the metadata text at the first blank line (with optional whitespace) and search only inside that header block. This keeps Version:-like strings in a package description from being matched. One focused regression test was added to test/test_python.py.

Scope

One line of parsing logic plus one test. No refactor, no new dependency, no unrelated file changes.

Disclosure

The investigation, reproduction, root-cause analysis and patch were prepared with AI assistance (Hermes). I reviewed the diff and the observed test output. Maintainer review is requested.

Tested

  • New regression test on unmodified HEAD: python -m pytest test/test_python.py -q -k reads_version_later_in_header — exit 1 (fails as expected).
  • Same test on the patched branch: exit 0.
  • python -m pytest test/test_python.py -q on the patched branch — exit 0, 7 passed.

Tests ran in a virtual environment with the repository installed via pip install -e ..

Not-tested

  • Full repository test suite, linters and CI were not run locally.
  • The published selenium-4.22.0 wheel was not downloaded or scanned end-to-end; verification used a METADATA fixture matching the header order from the issue.

Signed-off-by: saswatdutta1310 <241573095+saswatdutta1310@users.noreply.github.com>
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.

fix: PythonParser.run_checker truncates METADATA and PKG-INFO to 3 lines, dropping packages with later Name or Version headers

1 participant