modify Fonts Class and get_font function to load fonts from 2 possible locations
What changed, and why it matters
This commit simply teaches the app to look for font files in two folders instead of one. It is a routine feature change to support translated or additional fonts, not a security fix or vulnerability.
No security action required; review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change refactors the Fonts singleton from a single font_path to a list of font_paths, iterating over them when loading a TrueType/OpenType font. The second path points to resources/seedsigner-translations/fonts. Error handling is preserved: if no path yields the font, the last captured OSError is re-raised. No input validation, path traversal, cryptographic, or privilege changes are introduced.
Changed components
src/seedsigner/gui/components.py:Fonts class and get_font methodInspect captured patch +29 / −11
diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py
index d9a2e0b..ecbbf82 100644
--- a/src/seedsigner/gui/components.py
+++ b/src/seedsigner/gui/components.py
@@ -293,11 +293,19 @@ def load_image(image_name: str) -> Image.Image:
class Fonts(Singleton):
- font_path = os.path.join(
- pathlib.Path(__file__).parent.resolve().parent.resolve(),
- "resources",
- "fonts"
- )
+ font_paths = [
+ os.path.join(
+ pathlib.Path(__file__).parent.resolve().parent.resolve(),
+ "resources",
+ "fonts"
+ ),
+ os.path.join(
+ pathlib.Path(__file__).parent.resolve().parent.resolve(),
+ "resources",
+ "seedsigner-translations",
+ "fonts"
+ )
+ ]
fonts = {}
@classmethod
@@ -310,13 +318,23 @@ class Fonts(Singleton):
file_extension = "otf"
if size not in cls.fonts[font_name]:
- try:
- cls.fonts[font_name][size] = ImageFont.truetype(os.path.join(cls.font_path, f"{font_name}.{file_extension}"), size)
- except OSError as e:
- if "cannot open resource" in str(e):
- raise Exception(f"Font {font_name}.{file_extension} not found: {repr(e)}")
+
+ # loop over possible font locations and attempt to load font object
+ captured_exception = None
+ for font_path in cls.font_paths:
+ try:
+ cls.fonts[font_name][size] = ImageFont.truetype(os.path.join(font_path, f"{font_name}.{file_extension}"), size)
+ break
+ except OSError as e:
+ captured_exception = e
+ continue
+
+ # throw error at this point is font object was unable to be loaded
+ if size not in cls.fonts[font_name]:
+ if "cannot open resource" in str(captured_exception):
+ raise Exception(f"Font {font_name}.{file_extension} not found: {repr(captured_exception)}")
else:
- raise e
+ raise captured_exception
return cls.fonts[font_name][size]
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.