Skip to content

Avoid TOCTOU errors in cache initialization#10884

Merged
charliermarsh merged 1 commit intomainfrom
charlie/git
Apr 11, 2024
Merged

Avoid TOCTOU errors in cache initialization#10884
charliermarsh merged 1 commit intomainfrom
charlie/git

Conversation

@charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Apr 11, 2024

Summary

I believe this should close #10880? The .gitignore creation seems ok, since it truncates, but using cachedir::is_tagged followed by cachedir::add_tag is not safe, as cachedir::add_tag fails if the file already exists.

This also matches the structure of the code in uv.

Closes #10880.

@charliermarsh charliermarsh added the bug Something isn't working label Apr 11, 2024
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)

pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ scripts/validate_unwanted_patterns.py:428:3: E999 SyntaxError: unindent does not match any outer indentation level

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
E999 1 1 0 0 0

@charliermarsh charliermarsh merged commit 0cc154c into main Apr 11, 2024
@charliermarsh charliermarsh deleted the charlie/git branch April 11, 2024 16:09
Glyphack pushed a commit to Glyphack/ruff that referenced this pull request Apr 12, 2024
## Summary

I believe this should close
astral-sh#10880? The `.gitignore`
creation seems ok, since it truncates, but using `cachedir::is_tagged`
followed by `cachedir::add_tag` is not safe, as `cachedir::add_tag`
_fails_ if the file already exists.

This also matches the structure of the code in `uv`.

Closes astral-sh#10880.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error: Failed to initialize cache at <dir>/.ruff_cache: File exists (os error 17)

2 participants