Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix: reject invalid avatar focus sidecars

longmeidaoa7b484eaee8a
diff --git a/src/peach/web_contract.py b/src/peach/web_contract.py
index 033e65ee5..2a826c784 100644
--- a/src/peach/web_contract.py
+++ b/src/peach/web_contract.py
@@ -221,7 +221,8 @@ class WebContract:
return None
axis = focus.get("axis")
pct = focus.get("pct")
- if axis not in {"x", "y"} or not isinstance(pct, (int, float)):
+ if (axis not in {"x", "y"} or isinstance(pct, bool)
+ or not isinstance(pct, (int, float)) or not 0 <= pct <= 100):
return None
return {"axis": axis, "pct": int(pct)}
diff --git a/tests/test_rm_web.py b/tests/test_rm_web.py
index ef6070c8e..67d24a884 100644
--- a/tests/test_rm_web.py
+++ b/tests/test_rm_web.py
@@ -1157,8 +1157,14 @@ class AvatarFocusTests(unittest.TestCase):
'{"focus":{"axis":"z","pct":50}}', encoding="utf-8")
(self.avatars / "studio-12.face.json").write_text(
'{"focus":{"axis":"y","pct":"high"}}', encoding="utf-8")
+ (self.avatars / "creator-13.face.json").write_text(
+ '{"focus":{"axis":"x","pct":-20}}', encoding="utf-8")
+ (self.avatars / "series-14.face.json").write_text(
+ '{"focus":{"axis":"y","pct":true}}', encoding="utf-8")
self.assertIsNone(self.contract.avatar_focus("performer", 7900))
self.assertIsNone(self.contract.avatar_focus("studio", 12))
+ self.assertIsNone(self.contract.avatar_focus("creator", 13))
+ self.assertIsNone(self.contract.avatar_focus("series", 14))
class DuplicateDetectionTests(unittest.TestCase):