Skip to content

fix: evaluate full SPDX license expressions - #98

Open
mimran-khan wants to merge 5 commits into
NVIDIA:mainfrom
mimran-khan:fix/spdx-or-expression-truncated
Open

fix: evaluate full SPDX license expressions#98
mimran-khan wants to merge 5 commits into
NVIDIA:mainfrom
mimran-khan:fix/spdx-or-expression-truncated

Conversation

@mimran-khan

Copy link
Copy Markdown
Contributor

Summary

SPDX headers like MIT OR GPL-3.0 were truncated to MIT, so the copyleft half never ran and the license check passed. A plain GPL-3.0 header was already blocked.

I capture the full expression and fail closed if any symbol is on the blocklist. MIT OR MIT-0 still passes. Fixes #86.

Verification

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes
  • Ran make lint
  • Ran make test
  • Ran make build
  • Did not add credentials, private datasets, or proprietary benchmark content

Release Impact

  • Updated CHANGELOG.md

The header regex stopped at the first identifier, so MIT OR GPL-3.0
was recorded as MIT and allowed. Capture the whole expression and
fail closed if any symbol is blocked.

Fixes NVIDIA#86

Signed-off-by: mimran-khan <mohammed_imran.khan@outlook.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The focused license suite passes (28 tests), with Ruff and diff checks clean, but compound SPDX headers still pass in common block/HTML comment forms. Blocking reproduction is inline. The shared Gitleaks failure is from non-ancestor commits on an unrelated branch.


# SPDX header pattern for source files
SPDX_LICENSE_PATTERN = r"SPDX-License-Identifier:\s*([A-Za-z0-9.\-+]+)"
SPDX_LICENSE_PATTERN = r"SPDX-License-Identifier:\s*([^\n]+)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Stop the capture before comment terminators

Capturing the entire line leaves closing comment syntax attached to the final SPDX symbol. For example, /* SPDX-License-Identifier: MIT OR GPL-3.0 */ in a scanned .js file becomes MIT OR GPL-3.0 */; GPL-3.0 */ is treated as unknown, and default (non-strict) validation passes with only a warning. HTML-comment headers have the same problem. Please parse a valid SPDX expression without *//--> (ideally with the existing SPDX expression parser) so the blocked component cannot be hidden.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, /* SPDX-License-Identifier: MIT OR GPL-3.0 */ was capturing GPL-3.0 */ as the last symbol, so default mode only warned.

I strip */ and --> after the capture, then evaluate the expression as before. Added JS block-comment and HTML-comment cases; both fail closed on GPL-3.0.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for adding the block-comment and HTML cases. This still strips the terminator only when it is at the end of the line. With an inline block comment containing SPDX-License-Identifier: MIT OR GPL-3.0 followed by code on the same line, the GPL identifier retains the terminator and code suffix, so default validation passes with only an unknown-license warning. Please stop the capture at the first comment terminator wherever it occurs and add an inline-code regression.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch on inline block comments. _strip_spdx_capture now truncates at the first */ or --> anywhere in the captured span, not only at end-of-line. Added a regression with trailing code on the same line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Inline */ truncation is in _strip_spdx_capture now, with a same-line code suffix regression.

A JS or HTML SPDX header captured `MIT OR GPL-3.0 */` (or `-->`), so
the GPL half looked unknown and default validation warned instead of
blocking. Drop `*/` and `-->` before splitting the expression.

Fixes NVIDIA#86

Signed-off-by: mimran-khan <mohammed_imran.khan@outlook.com>
@mimran-khan

Copy link
Copy Markdown
Contributor Author

Merged main and the SPDX comment-terminator fix is still on branch. Ready for re-review.

Stop SPDX extraction at the first */ or --> anywhere in the captured line,
not only when the terminator is at the end. Add a regression for inline block
comments that share a line with trailing source code.
@chrisknvidia

Copy link
Copy Markdown
Collaborator

@mimran-khan : Please resolve the merge conflicts.

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.

[BUG]: SPDX-License-Identifier "MIT OR GPL-3.0" is truncated to MIT and allowed

3 participants