From 642ea5f20d2c349a399f21e0a74906b3493d0041 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:30:06 +0000 Subject: [PATCH 1/2] fix: handle non-numeric icon keys in get_extension_icon to prevent ValueError crash When a Chrome extension's manifest.json uses non-numeric icon size keys (e.g. "48x48" instead of "48"), the call to max(..., key=lambda x: int(x)) would raise ValueError. Although caught by the outer except block, this caused icon retrieval to silently fail and return a placeholder image. Fix: filter manifest icon keys to only those that are digit-only strings before calling max(), and raise a clear ValueError when none are found so the existing except handler produces a descriptive warning log. Agent-Logs-Url: https://github.com/Th-Shivam/ExtensionShield/sessions/318c38db-0228-407d-b8a3-98a363e523e3 Co-authored-by: Th-Shivam <169958957+Th-Shivam@users.noreply.github.com> --- src/extension_shield/api/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/extension_shield/api/main.py b/src/extension_shield/api/main.py index 3ebbc4c..fe3bba7 100644 --- a/src/extension_shield/api/main.py +++ b/src/extension_shield/api/main.py @@ -4035,8 +4035,12 @@ def _persisted_icon_response() -> Optional[Response]: # Check icons object in manifest manifest_icons = manifest.get("icons", {}) if manifest_icons: - # Get the largest icon - largest_size = max(manifest_icons.keys(), key=lambda x: int(x)) + # Get the largest icon - only consider numeric keys (e.g. "128", "64") + # Some extensions use non-numeric keys like "48x48" which would cause ValueError + numeric_keys = [k for k in manifest_icons.keys() if isinstance(k, str) and k.isdigit()] + if not numeric_keys: + raise ValueError(f"No numeric icon size keys found in manifest: {list(manifest_icons.keys())}") + largest_size = max(numeric_keys, key=lambda x: int(x)) icon_rel_path = manifest_icons[largest_size] manifest_icon_path = os.path.join(extracted_path, icon_rel_path) From 9f72592f89245157e27f317a4d1f4749b22952af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 4 Apr 2026 08:31:23 +0000 Subject: [PATCH 2/2] fix: clarify isinstance guard comment per code review Agent-Logs-Url: https://github.com/Th-Shivam/ExtensionShield/sessions/318c38db-0228-407d-b8a3-98a363e523e3 Co-authored-by: Th-Shivam <169958957+Th-Shivam@users.noreply.github.com> --- src/extension_shield/api/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/extension_shield/api/main.py b/src/extension_shield/api/main.py index fe3bba7..50da945 100644 --- a/src/extension_shield/api/main.py +++ b/src/extension_shield/api/main.py @@ -4037,6 +4037,7 @@ def _persisted_icon_response() -> Optional[Response]: if manifest_icons: # Get the largest icon - only consider numeric keys (e.g. "128", "64") # Some extensions use non-numeric keys like "48x48" which would cause ValueError + # isinstance guard handles edge cases where manifest was parsed outside of json.load numeric_keys = [k for k in manifest_icons.keys() if isinstance(k, str) and k.isdigit()] if not numeric_keys: raise ValueError(f"No numeric icon size keys found in manifest: {list(manifest_icons.keys())}")