Skip to content

python: reject a bare str or bytes in identify_paths (#1472) - #1476

Open
kaluli123123 wants to merge 7 commits into
google:mainfrom
kaluli123123:fix/identify-paths-reject-str
Open

kaluli123123 wants to merge 7 commits into
google:mainfrom
kaluli123123:fix/identify-paths-reject-str

Conversation

@kaluli123123

@kaluli123123 kaluli123123 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1472.

Reject bare str/bytes in identify_paths() while preserving path sequences and identify_path(str). Merged current main (8461733), retaining the upstream native batched pipeline and its documentation.

Python 3.13: focused regression and non-slow suite passed (41 passed, 1 skipped); lock, Ruff, formatting, ty, copyright, documentation, KB sync and real API/CLI/module smokes passed.

Current-head workflows need maintainer authorization; formal approval is still required.

`str` and `bytes` are registered as `collections.abc.Sequence`, so the
container guard in `identify_paths()` let them through. The string was then
iterated character by character and the call returned one bogus
`MagikaResult` per character instead of raising `TypeError` — including a
`Status.OK` `directory` result for the `.` component.

Exclude `str`/`bytes` from the guard, which is the only place this can be
caught: a bare `str` type-checks fine against
`Sequence[Union[str, os.PathLike]]`.

Fixes google#1472
@ebursztein

Copy link
Copy Markdown
Collaborator

Thank you! I checked this against the current main (Python on the Rust library): it still merges cleanly, the bug still reproduces without it, and the full Python suite passes with it, including your new test. It's listed in #1537 as ready to merge.

@kaluli123123

Copy link
Copy Markdown
Contributor Author

Rebased-free update: merged the current main into this branch with a merge commit (no rebase, no force-push), so the branch is no longer behind.

  • Merged base: 9f2f5281a215f71ebfab72f90637df541e4a7113 (origin/main)
  • New head: 2bc0427c853de85a59fb88f12f5756d37426682c
  • No conflicts; the fix itself is unchanged.

Validation run locally in python/ at the new head (commands from python/justfile):

  • uv run pytest tests -m "not slow" -q -> 41 passed, 1 skipped, 1 deselected in 1.21s
  • uv lock --check -> resolved, up to date
  • uv run ruff check -> All checks passed!
  • uv run ruff format --check -> 23 files already formatted
  • uv run ty check -> All checks passed!
  • uv run ../scripts/check_copyright.py -> All files have valid copyright.

After the push, mergeStateStatus is no longer BEHIND; GitHub reports MERGEABLE / BLOCKED and the visible checks are check-changes: pass, cla/google: pass, with the zizmor jobs skipping. The remaining workflows appear to need maintainer approval to run on this fork branch.

@kaluli123123

Copy link
Copy Markdown
Contributor Author

Synced with latest main (merge commit, no conflicts). New head: c88f1f5. The branch is no longer behind the base.

Local verification in python/ with uv:

  • uv sync --locked --all-extras --dev — lockfile in sync
  • uv run ruff check — All checks passed!
  • uv run ruff format --check — 23 files already formatted
  • uv run ty check — All checks passed!
  • uv run pytest tests -m "not slow" — 41 passed, 1 skipped, 1 deselected

The fix and its regression test are unchanged by the merge.

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

2 participants