Skip to content

fix: raise a clear error for an spdx_id with multiple colons - #902

Open
Atishyy27 wants to merge 1 commit into
spdx:mainfrom
Atishyy27:fix/901-multi-colon-spdx-id
Open

fix: raise a clear error for an spdx_id with multiple colons#902
Atishyy27 wants to merge 1 commit into
spdx:mainfrom
Atishyy27:fix/901-multi-colon-spdx-id

Conversation

@Atishyy27

Copy link
Copy Markdown

Fixes #901.

Problem

get_full_element_spdx_id unpacked element.spdx_id.split(":") into exactly two values, so an spdx_id containing more than one colon raised ValueError: too many values to unpack (expected 2) during bump_spdx_document.

validate_spdx_id already rejects such ids with a descriptive message, but the bump path can run without validation — pyspdxtools3 --novalidation, or any direct bump_spdx_document() library call — so a malformed id from a third-party SBOM reaches this line and crashes with an internal unpack error.

Change

Check the split length first and raise the same descriptive error the validator uses. Single-colon (external document ref) and no-colon ids are unaffected.

Testing

Added test_bump_external_element_with_malformed_spdx_id in tests/spdx3/bump/test_external_element_bump.py.

  • Before the fix, it fails with too many values to unpack (expected 2).
  • After the fix, it passes; the existing test_bump_external_elements still passes.

black, isort and flake8 are clean on both changed files.

get_full_element_spdx_id unpacked spdx_id.split(":") into exactly two
values, so an id containing more than one colon raised
"ValueError: too many values to unpack (expected 2)" during
bump_spdx_document. validate_spdx_id already rejects such ids with a
descriptive message, but the bump path can run without validation
(pyspdxtools3 --novalidation, or a direct library call).

Check the split length and raise the same descriptive error instead.

Fixes spdx#901

Signed-off-by: Atishyy27 <[email protected]>
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.

bump_spdx_document crashes with 'too many values to unpack' on an spdx_id containing more than one colon

1 participant