Skip to content

fix(python): reject a bare str in identify_paths (#1472) - #1647

Open
volt69506-eng wants to merge 2 commits into
google:mainfrom
volt69506-eng:fix/identify-paths-bare-str
Open

volt69506-eng wants to merge 2 commits into
google:mainfrom
volt69506-eng:fix/identify-paths-bare-str

Conversation

@volt69506-eng

Copy link
Copy Markdown

Closes #1472

What

Magika.identify_paths() is documented and type-hinted as taking a Sequence[Union[str, os.PathLike]], and it raises TypeError for non-sequence input. A bare str (or bytes) is registered as a collections.abc.Sequence, so it passed the guard and was iterated character by character: m.identify_paths("code.py") silently returned seven bogus MagikaResults instead of raising. The issue's reproduction is exactly that common typo.

Change

Reject str/bytes explicitly before the sequence check:

if isinstance(paths, (str, bytes)) or not isinstance(paths, Sequence):
    raise TypeError("Input paths should be of type Sequence[Path]")

Valid input is unchanged: ["code.py"], [Path(...)], tuples and generators still take the normal path.

TDD

  • test: identify_paths rejects a bare str was committed first. Against main's code the new assertions fail with Failed: DID NOT RAISE TypeError (RED).
  • The fix: commit makes the same test pass (GREEN).
  • Full module suite: 42 passed, 1 skipped.
  • Branch is based on current google/magika@9f2f528.

@volt69506-eng
volt69506-eng force-pushed the fix/identify-paths-bare-str branch from 93dab38 to aa167fc Compare November 27, 2026 18:11

This branch has not been deployed

No deployments
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.

python: identify_paths() silently accepts a bare str and returns one bogus result per character

1 participant