From 028d2ca5088085b25ae6bb66f9671231dc17d523 Mon Sep 17 00:00:00 2001 From: devs6186 Date: Thu, 19 Feb 2026 03:42:46 +0530 Subject: [PATCH 1/3] ida-explorer: fix TypeError when sorting mixed address types When a feature has multiple locations and those locations contain a mix of integer-based addresses (e.g. AbsoluteVirtualAddress) and non-integer addresses (e.g. _NoAddress), calling sorted() raises a TypeError because Python falls back to the reflected comparison (__gt__) which is not defined on _NoAddress. Add a sort key to sorted() that places integer-based addresses first (sorted by value) and non-integer addresses last, avoiding the cross-type comparison. Fixes #2195 --- CHANGELOG.md | 1 + capa/ida/plugin/model.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3169082671..d5831e4a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - webui: fix 404 for "View rule in capa-rules" by using encodeURIComponent for rule name in URL @devs6186 #2482 ### capa Explorer IDA Pro plugin +- ida-explorer: fix TypeError when sorting locations containing mixed address types @devs6186 #2195 ### Development diff --git a/capa/ida/plugin/model.py b/capa/ida/plugin/model.py index 046dc1ea3f..708f8a4945 100644 --- a/capa/ida/plugin/model.py +++ b/capa/ida/plugin/model.py @@ -613,7 +613,9 @@ def render_capa_doc_feature_node( # feature has multiple children, nest under one parent feature node parent2 = CapaExplorerFeatureItem(parent, display) - for location in sorted(locations): + # use a key to avoid TypeError when mixing address types (e.g. AbsoluteVirtualAddress and _NoAddress) + # integer-based addresses sort by value; non-integer addresses (like _NoAddress) sort last + for location in sorted(locations, key=lambda loc: (0, int(loc)) if isinstance(loc, int) else (1, 0)): self.render_capa_doc_feature(parent2, match, feature, location, doc) return parent2 From 7cd6bbae6a82bde803f98e324051a09d34d1fb89 Mon Sep 17 00:00:00 2001 From: devs6186 Date: Fri, 20 Feb 2026 05:13:02 +0530 Subject: [PATCH 2/3] ida-explorer: fix comparison at source so sorted(locations) works everywhere Implement the gt solution per review: fix comparison for all addresses so we can use sorted(locations) / sorted(addrs) consistently without per-call-site sort keys. - Add _NoAddress.__gt__ so mixed-type comparison works: (real_address < NO_ADDRESS) invokes it and NoAddress sorts last. Avoids TypeError when sorting AbsoluteVirtualAddress with _NoAddress. - In ida/plugin/model.py, use sorted(locations) instead of a custom key. view.py (lines 1054, 1077) already use sorted(); they now work with mixed address types without change. Fixes #2195 --- capa/features/address.py | 5 +++++ capa/ida/plugin/model.py | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/capa/features/address.py b/capa/features/address.py index eb708a3dcd..31b5d8203e 100644 --- a/capa/features/address.py +++ b/capa/features/address.py @@ -189,6 +189,11 @@ def __eq__(self, other): def __lt__(self, other): return False + def __gt__(self, other): + # Mixed-type comparison: (real_address < NO_ADDRESS) invokes this so sort works. + # NoAddress sorts last. + return other is not self + def __hash__(self): return hash(0) diff --git a/capa/ida/plugin/model.py b/capa/ida/plugin/model.py index 708f8a4945..046dc1ea3f 100644 --- a/capa/ida/plugin/model.py +++ b/capa/ida/plugin/model.py @@ -613,9 +613,7 @@ def render_capa_doc_feature_node( # feature has multiple children, nest under one parent feature node parent2 = CapaExplorerFeatureItem(parent, display) - # use a key to avoid TypeError when mixing address types (e.g. AbsoluteVirtualAddress and _NoAddress) - # integer-based addresses sort by value; non-integer addresses (like _NoAddress) sort last - for location in sorted(locations, key=lambda loc: (0, int(loc)) if isinstance(loc, int) else (1, 0)): + for location in sorted(locations): self.render_capa_doc_feature(parent2, match, feature, location, doc) return parent2 From 872c7e30bb13fef573bce652f8898cd19d7c5a25 Mon Sep 17 00:00:00 2001 From: devs6186 Date: Tue, 24 Feb 2026 08:36:45 +0530 Subject: [PATCH 3/3] changelog: move address sort fix to Bug Fixes section Per maintainer feedback: fix applies beyond ida-explorer. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5831e4a37..f30a4cc288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,12 +40,12 @@ - lint: disable rule caching during linting @Maijin #2817 - vmray: skip processes with invalid PID or missing filename @EclipseAditya #2807 - render: use default styling for dynamic -vv API/call details so they are easier to see @devs6186 #1865 +- address: fix TypeError when sorting locations containing mixed address types @devs6186 #2195 ### capa Explorer Web - webui: fix 404 for "View rule in capa-rules" by using encodeURIComponent for rule name in URL @devs6186 #2482 ### capa Explorer IDA Pro plugin -- ida-explorer: fix TypeError when sorting locations containing mixed address types @devs6186 #2195 ### Development