#32328·matplotlib

[Bug]: macOS font discovery raises KeyError('_items') for an incomplete system_profiler font record

Author: iskandrCreated Sep 9, 2026Updated Sep 13, 2026
LabelsOS: Applestatus: needs clarificationtopic: text/fontsfirst-contribution

Summary

On macOS arm64, importing matplotlib.pyplot through DNA Chisel during a command-line smoke test failed in _get_macos_fonts with KeyError: '_items'. Matplotlib is 3.10.8, Python 3.12.6. The process was running with restricted filesystem access; Matplotlib could not write its default cache directory and created a temporary cache before scanning fonts.

The current implementation catches subprocess/plist parsing errors but assumes every successfully decoded record contains _items: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/font_manager.py

Minimal parser-boundary reproduction

In an environment where font_manager can already be imported:

python
import plistlib
from unittest.mock import patch
from matplotlib import font_manager

font_manager._get_macos_fonts.cache_clear()
payload = plistlib.dumps([{"_name": "Fonts"}])
with patch("subprocess.check_output", return_value=payload):
    font_manager._get_macos_fonts()

The payload is a minimal synthetic reproduction of the missing-key condition, not a capture of the entire system_profiler response. The actual CLI traceback ended at:

font_manager.py, in _get_macos_fonts
    return [Path(entry["path"]) for entry in d["_items"]]
KeyError: '_items'

Expected behavior

Treat unavailable/incomplete system font discovery as an empty or partial result, consistent with the existing OSError/subprocess-error fallbacks, rather than making pyplot import fail. A regression could cover missing _items and entries without a path.

This is a robustness report; no change to font selection semantics is requested when system_profiler returns a complete record. Downstream discovery: openvax/vaxrank#428.