You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Security] Unhandled exception in .metadata.json parsing terminates ranger #3232
Unhandled exception in .metadata.json parsing terminates ranger
CWE
CWE-248 (Uncaught Exception)
Affected
ranger 1.9.4 (git 51e19b8) and likely all prior versions
Tested
ranger 1.9.4, Python 3.13.12, x86_64 Linux
When ranger browses a directory containing a malformed .metadata.json file, the JSON parser raises a ValueError that is not caught anywhere in the draw call chain. The exception propagates to the outermost handler in main.py, which prints a traceback and exits. The user loses their ranger session without any warning or recovery prompt.
Description
_get_metafile_content() in ranger/core/metadata.py reads and parses .metadata.json files. When json.load() fails, it re-raises as a ValueError (line 126):
A malformed .metadata.json can be placed in any shared or world-writable directory (e.g. /tmp, a project repository, a downloaded archive), requiring no elevated privileges. Accidentally malformed files from third-party tools that write a .metadata.json with non-standard content trigger the same crash.
Observe that an unhandled ValueError is raised. In a live ranger session this exception terminates the process.
Error Output
Traceback (most recent call last):
File "ranger/core/metadata.py", line 124, in _get_metafile_content
entries = json.load(fobj)
...
File "ranger/core/metadata.py", line 45, in get_metadata
return ostruct(copy.deepcopy(self._get_entry(filename)))
File "ranger/core/metadata.py", line 99, in _get_entry
entries = self._get_metafile_content(metafile)
File "ranger/core/metadata.py", line 126, in _get_metafile_content
raise ValueError("Failed decoding JSON file %s" % metafile)
ValueError: Failed decoding JSON file /tmp/testdir/.metadata.json
Suggested Fix
Add ValueError to the exception tuple in the inner except clause of get_metadata() so that a JSON parse failure is handled gracefully and returns an empty metadata struct instead of propagating:
This fix was applied and confirmed: get_metadata() now returns an empty DefaultOpenStruct without raising when .metadata.json contains invalid JSON. ranger continues operating normally and the file's entry is displayed without metadata.
Credits
This issue was identified by Michał Majchrowicz and Marcin Wyczechowski, members of the AFINE Team.
Disclosure Policy
We follow a 90-day coordinated disclosure policy. We are committed to working with the ranger maintainers to resolve this issue before any public disclosure. If we do not receive a response within 90 days of the initial report, we reserve the right to publicly disclose the details of this vulnerability.
Yes I agree. Maybe a better fix is to treat malformed .metadata.json as a
recoverable error: notify the user, skip the broken metadata, and continue
browsing instead of terminating ranger.
From what I can tell, metadata is normally cached for the lifetime of the session, so it is not reread very often unless the cache is reset.
The important part here is the broken-file case: if we do not cache that state, ranger will keep reopening and reparsing the same malformed .metadata.json during redraws, because metadata lookup happens in the draw path.
So I think it is worth keeping problematic metafiles in memory for the current session as well, and treating them as empty metadata until :reset or restart. That avoids repeated parse attempts and repeated noise for the same broken file.
Activity
toonn commentedon Jul 5, 2026
The suggested fix just silences the error. A proper fix should notify the user of the problem.
sectroyer commentedon Jul 5, 2026
Yes I agree. Maybe a better fix is to treat malformed
.metadata.jsonas arecoverable error: notify the user, skip the broken metadata, and continue
browsing instead of terminating ranger.
Something along these lines should address that:
This should keep ranger usable, make the problem visible to the user, and avoid
repeated redraw spam from the same malformed metadata file.
toonn commentedon Aug 15, 2026
That seems like an acceptable patch to me. How often is the metadata reread, to see if keeping problematic entries in memory is worth it?
sectroyer commentedon Aug 24, 2026
From what I can tell, metadata is normally cached for the lifetime of the session, so it is not reread very often unless the cache is reset.
The important part here is the broken-file case: if we do not cache that state, ranger will keep reopening and reparsing the same malformed
.metadata.jsonduring redraws, because metadata lookup happens in the draw path.So I think it is worth keeping problematic metafiles in memory for the current session as well, and treating them as empty metadata until
:resetor restart. That avoids repeated parse attempts and repeated noise for the same broken file.