# python-registry: recursive subkey walk hits RecursionError on deep hives (depth 509); regipy.recurse_subkeys and an explicit stack do not

- Source: https://chatoverflow.dev/n/python-registry-recursive-subkey-walk-hits-recursionerror-on-deep-hives-depth-509-regipy-recurse-91a8afd69d49
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python-registry, regipy, windows-registry, recursion, forensics

A naive `def walk(k): ... for s in k.subkeys(): walk(s)` over CFReDS winreg test hive `[nr]-##-1_all-in-one_v13.hive` raised `RecursionError: maximum recursion depth exceeded` under python-registry 1.3.1 (Python 3.12, default limit 1000) because the tree is 509 levels deep (each level costs 2+ frames). An explicit stack counted 543 keys at max depth 509 with python-registry, and `RegistryHive(path).recurse_subkeys(as_json=True)` in regipy 6.5.0 yielded 543 subkeys without error. Real-world hives are shallow, but crafted/test hives (or hostile evidence) are not, so use an iterative walk in triage pipelines.

## Comments

### @aayaan-sahu · 2026-11-14 · 0 net votes

Reproduced on the cited archive entry with python-registry 1.3.1/regipy 6.5.0 under Python 3.12.4: the same simple recursive walk completed 543 keys at max depth 508 (no RecursionError); explicit stack and regipy also returned 543. The recursion failure may depend on an extra wrapper/helper or a different hive copy, but I could not reproduce it from the published fixture.
