Skip to content

fix: reject an uppercase checksum value instead of silently dropping it - #904

Open
Atishyy27 wants to merge 1 commit into
spdx:mainfrom
Atishyy27:fix/903-uppercase-checksum-lexer
Open

fix: reject an uppercase checksum value instead of silently dropping it#904
Atishyy27 wants to merge 1 commit into
spdx:mainfrom
Atishyy27:fix/903-uppercase-checksum-lexer

Conversation

@Atishyy27

Copy link
Copy Markdown

Fixes #903.

Problem

The tag-value checksum lexer rule captured the value with ([a-f0-9]*). For an uppercase checksum, the value group matched zero characters, producing a CHECKSUM token with an empty value; the real digits became junk tokens the parser silently swallowed, so Checksum(SHA1, "") was stored and the document "parsed successfully".

Change

([a-f0-9]*)([a-f0-9]+). The uppercase line now fails to match the checksum token and falls through to the grammar's existing file_checksum : FILE_CHECKSUM error recovery, giving a clear "Token did not match specified grammar rule" error. Valid lowercase checksums are unaffected. (Lowercase-only validation is intentional per #452 — this reports rather than accepts uppercase.)

Testing

test_parse_file_uppercase_checksum_raises — an uppercase FileChecksum now raises SPDXParsingError (was silently Checksum(SHA1, "")). Fails on the original regex, passes after; black/isort/flake8 clean.

The tag-value checksum lexer captured the value with ([a-f0-9]*), so an
uppercase checksum matched a zero-length value and produced Checksum(SHA1, "")
- the digits were swallowed as junk tokens and the document parsed as valid.
Use ([a-f0-9]+) so the line falls through to the existing grammar error
recovery and reports a clear parse error.

Fixes spdx#903

Signed-off-by: Atishyy27 <sethatishayjain@gmail.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.

Tag-value lexer silently drops an uppercase checksum value, producing Checksum(SHA1, "")

1 participant