ida-explorer: fix TypeError when sorting locations with mixed address types (#2867)

* 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

* 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

* changelog: move address sort fix to Bug Fixes section

Per maintainer feedback: fix applies beyond ida-explorer.
This commit is contained in:
Devyansh Somvanshi
2026-02-26 22:03:05 +05:30
committed by GitHub
parent 10dfd287b4
commit e1ffa1dd09
2 changed files with 6 additions and 0 deletions

View File

@@ -40,6 +40,7 @@
- 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

View File

@@ -189,6 +189,11 @@ class _NoAddress(Address):
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)