bug: Unreachable JSON extension and format validation in validate_input_path
Maintainers usually reply within 2 days
@0Cymantek0 is already working on this.
Since Oct 11, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in src/scancode/cli.py at validate_input_path, around lines 194-203, where the unconditional raise makes the JSON extension and format checks unreachable. Read the from_json branch and the is_file condition, then run the reproduction with png.png to see the generic error. Done when --from-json on a non-.json file raises not a JSON file with a .json extension early, and the regression test added to tests/scancode/test_cli.py passes.
Written by the indexing model from the issue text.
Description
Description
Lines 198–203 in validate_input_path are unreachable dead code. They are placed after an unconditional raise on line 197, inside the same if from_json and not is_file(...) block. Python never executes statements after an unconditional raise in the same block.
Buggy code (permalink):
if from_json and not is_file(location=inp, follow_symlinks=True):
# extra JSON validation
raise click.BadParameter(f"JSON input: {inp!r} is not a file")
if not inp.lower().endswith(".json"): # unreachable
raise click.BadParameter(f"JSON input: {inp!r} is not a JSON file with a .json extension")
with open(inp) as js: # unreachable
start = js.read(100).strip()
if not start.startswith("{"): # unreachable
raise click.BadParameter(f"JSON input: {inp!r} is not a well formed JSON file")
There is a second structural problem: even if the raise were absent, the extension and format checks are inside the if from_json and not is_file(...) block, so they would only run when the input is not a file — the opposite of the intended condition. They should run when the input is a file.
Observed behavior: Running --from-json with a real file whose name does not end in .json (e.g. png.png) produces no early validation error. The scan proceeds and fails later with a generic Input JSON scan file(s) is not valid JSON message instead of the intended not a JSON file with a .json extension error.
Expected behavior: validate_input_path raises a click.BadParameter with message not a JSON file with a .json extension before the scan begins.
How To Reproduce
- Confirm the dead code structurally:
python3 -c "
src = open('src/scancode/cli.py').read()
lines = src.splitlines()
for i, l in enumerate(lines[194:204], start=195):
print(i, repr(l))
"
Lines 198–203 are all indented inside the if from_json and not is_file(...) block and appear after the raise on line 197.
- Run a scan with
--from-jsonagainst a real non-JSON file:
scancode --from-json tests/scancode/data/various-inputs/png.png --json-pp -
The command does not produce not a JSON file with a .json extension. It instead emits Input JSON scan file(s) is not valid JSON, confirming the early check never executes.
Reproducing test
The following test currently fails on the unfixed code and is the concrete proof the bug is real. It is not a fix — it is a regression test that documents the broken behavior:
def test_scan_validates_json_extension_for_from_json_input():
test_file = test_env.get_test_loc('various-inputs/png.png')
result = run_scan_click(
[
'--from-json',
test_file,
'--json-pp',
'-',
],
expected_rc=2,
retry=False,
)
# FAILS on buggy code: output contains 'Input JSON scan file(s) is not valid JSON'
# PASSES on fixed code: output contains the early validation error
assert 'not a JSON file with a .json extension' in result.output
Add to tests/scancode/test_cli.py.
System configuration
- OS: Linux (Ubuntu)
- scancode-toolkit version: commit
5e8448ecf2397c6eb7e7eb50326c8c880d9b598b - Installation method: source
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 871
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 3
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorPossibly taken @Shubham-dev-stack claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainers usually reply within 2 days
-
package-lock.json dependencies report file_references as a list inside a listPossibly taken @Anbarasu2410 claimed this 9 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
aboutcode-org/scancode-toolkit#5449 · 4 comments ·
Maintainers usually reply within 2 days
-
scancode aborts when encountering a broken RPM archivePossibly taken @Ashutosh-Panda2004 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
aboutcode-org/scancode-toolkit#5407 · 3 comments ·
Maintainers usually reply within 2 days
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 Half a day Newbie friendliness 65/100
aboutcode-org/scancode-toolkit#5405 · 1 comment ·
Maintainers usually reply within 2 days
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsPossibly taken @RohitSutar1823 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainers usually reply within 2 days
All issues in aboutcode-org/scancode-toolkit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
openedx/xblock-lti-consumer#765 ·
Maintainers usually reply within 1 day