Fix TOCTOU Race Conditions when creating directories (#4587)

* fixed division by 0

* fixed division by 0

* fixed division by 0

* updated lock file

* Revert "fixed division by 0"

This reverts commit b916a0c9c9.

* Add tests for turn_animation_into_updater with zero/negative run_time

* updated lock file

* tests

---------

Co-authored-by: Benjamin Hackl <mail@behackl.dev>
This commit is contained in:
Sacha 2026-02-11 01:00:40 -08:00 committed by GitHub
commit 7efa45492f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 9 deletions

View file

@ -801,8 +801,7 @@ class Text(SVGMobject):
line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR
dir_name = config.get_dir("text_dir")
if not dir_name.is_dir():
dir_name.mkdir(parents=True)
dir_name.mkdir(parents=True, exist_ok=True)
hash_name = self._text2hash(color)
file_name = dir_name / (hash_name + ".svg")
@ -1349,8 +1348,7 @@ class MarkupText(SVGMobject):
line_spacing /= TEXT2SVG_ADJUSTMENT_FACTOR
dir_name = config.get_dir("text_dir")
if not dir_name.is_dir():
dir_name.mkdir(parents=True)
dir_name.mkdir(parents=True, exist_ok=True)
hash_name = self._text2hash(color)
file_name = dir_name / (hash_name + ".svg")

View file

@ -153,15 +153,14 @@ def add_version_before_extension(file_name: Path) -> Path:
def guarantee_existence(path: Path) -> Path:
if not path.exists():
path.mkdir(parents=True)
path.mkdir(parents=True, exist_ok=True)
return path.resolve(strict=True)
def guarantee_empty_existence(path: Path) -> Path:
if path.exists():
shutil.rmtree(str(path))
path.mkdir(parents=True)
path.mkdir(parents=True, exist_ok=True)
return path.resolve(strict=True)

View file

@ -103,8 +103,7 @@ def generate_tex_file(
output = tex_template.get_texcode_for_expression(expression)
tex_dir = config.get_dir("tex_dir")
if not tex_dir.exists():
tex_dir.mkdir()
tex_dir.mkdir(parents=True, exist_ok=True)
result = tex_dir / (tex_hash(output) + ".tex")
if not result.exists():