Skip to content

fix: add missing VmFlags to proc_pid_smaps parser#695

Open
lawrence3699 wants to merge 1 commit intokellyjonbrazil:masterfrom
lawrence3699:fix/smaps-wf-vmflag-keyerror
Open

fix: add missing VmFlags to proc_pid_smaps parser#695
lawrence3699 wants to merge 1 commit intokellyjonbrazil:masterfrom
lawrence3699:fix/smaps-wf-vmflag-keyerror

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #681

Problem

The proc_pid_smaps parser crashes with a KeyError when /proc/<pid>/smaps output contains VmFlags not present in vmflags_map. The wf (wipe on fork) flag, available since Linux 4.14, triggers this crash:

VmFlags: rd wr mr mw me nr wf dd sd dp
                             ^^
KeyError: 'wf'

Fix

  1. Add three missing kernel VmFlags to the map: wf (wipe on fork), um (userfaultfd missing pages tracking), uw (userfaultfd write-protect pages tracking).
  2. Change the lookup from vmflags_map[x] to vmflags_map.get(x, x) so any future unrecognized flags fall back to their raw abbreviation instead of crashing.

Validation

  • Reproduced the KeyError before the fix
  • All existing test_proc_pid_smaps tests pass
  • Added regression test with a fixture containing the wf flag

Add wf (wipe on fork), um (userfaultfd missing), and uw (userfaultfd
write-protect) flags to vmflags_map. These kernel flags were missing
and caused a KeyError crash when encountered in /proc/<pid>/smaps.

Also use dict.get() for the VmFlags lookup so that any future
unrecognized flags fall back to their raw abbreviation instead of
crashing.

Fixes kellyjonbrazil#681
Copilot AI review requested due to automatic review settings April 12, 2026 20:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in the proc_pid_smaps parser when /proc/<pid>/smaps contains previously-unmapped VmFlags values (issue #681), by expanding the known VmFlags map and making the pretty-name lookup resilient to unknown flags.

Changes:

  • Add missing VmFlags entries (wf, um, uw) to the parser’s vmflags_map.
  • Replace direct vmflags_map[x] indexing with vmflags_map.get(x, x) to avoid KeyError on future/unknown flags.
  • Add a regression test fixture and test case covering the wf flag.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
jc/parsers/proc_pid_smaps.py Adds missing VmFlags and prevents crashes by using a safe lookup fallback.
tests/test_proc_pid_smaps.py Loads the new fixture and adds a regression test for wf.
tests/fixtures/linux-proc/pid_smaps_wf_flag New smaps fixture containing the wf VmFlag.
tests/fixtures/linux-proc/pid_smaps_wf_flag.json Expected parsed JSON output including VmFlags_pretty with “wipe on fork”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--proc-pid-smaps breaks on wf (write-on-fork) flag

2 participants