Repository navigation
Fix a use-after-free in DANA's merge_groups and stale neighbors after split_group - #703
Merged
Merged
Conversation
… split_group merge_groups erased the gate set of a merged group and only then iterated it to point its gates to the new group. With libc++ the loop silently did nothing, so the gates kept pointing to the old group; with libstdc++ it read freed memory and failed with "unordered_map::at" (an IndexError in Python), typically already on the first merge. The gates are now reassigned before the old group is erased. merge_groups also kept the iterators to the signals, successors, and predecessors of the old group while inserting the new group, which may rehash these maps; it now moves or copies them first. split_group did not update the neighbors of the split group: their successors and predecessors still contained the old group and not the new ones, so a later merge_groups of such a neighbor failed. The neighbors now refer to the new groups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dataflow analysis had no tests, so CI never ran most of it. runTest-dataflow builds a netlist of four 8-bit registers that read each other in a loop, two of them also themselves, with an enable or a reset input each, and checks - the configuration: defaults, setters, gate and control pin types, known groups and known structures, and a configuration without a netlist, - the analysis: incomplete configurations, the registers it finds, the dataflow graph between groups and between gates, the control nets, the target gate types, known groups, and the further options, - the result: groups as lists, writing DOT and text files, creating modules with their names, nesting, suffixes, and pin groups, and merging and splitting groups, after which every gate must be in exactly one group whose successors and predecessors are those of its gates, - the plugin: its interface, the command line, and the GUI extension. Without the fix of merge_groups and split_group in the previous commit, four of the 26 tests fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julianspeith
enabled auto-merge (squash)
November 30, 2026 07:48
julianspeith
disabled auto-merge
November 30, 2026 07:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Result::merge_groupsread the gates of a merged group after erasing them. Depending on the standard library this either left gates pointing to groups that no longer exist (libc++, silently) or failed withunordered_map::at(libstdc++, anIndexErrorin Python).Result::split_grouphad a related bug: the neighbors of a split group kept referring to the old group, so a latermerge_groupsinvolving such a neighbor failed as well.None of this was caught because the dataflow analysis had no tests. This PR adds
runTest-dataflow, which covers the plugin's functionality, not only these two bugs.Cause
The loop that moves the gates to the new group iterates a reference into the map entry that was just erased. With libc++ the freed set usually looks empty, so the loop does nothing and every merged gate keeps its old group ID in
m_parent_group_of_gate. With libstdc++ the loop reads stale gates andat()throws.The same function also kept iterators into
m_group_signals,m_group_successorsandm_group_predecessorsacrossoperator[]on the target group, which can rehash the map and invalidate them.In
split_group, the old group's entry was removed, but its predecessors and successors still listed it, and they were never told about the new groups.Change
merge_groupsreassigns the gates before erasing the old group, moves the signals out before erasing their entry, and iterates copies of the successor and predecessor sets.split_groupremoves the old group from its neighbors and adds the new groups to them.plugins/dataflow_analysis/testadds the plugin's first test,runTest-dataflow(26 tests), on a netlist of four 8-bit registers that feed each other, with self-loops, enable and reset inputs, and a shared clock:get_groups_as_list;write_dotandwrite_txt(content, filters, extension replacement, directories, empty path);create_modules(names, gates, filters, reruns, nesting, suffixes, pin groups and prefixes)CHANGELOG.mdhas entries for both fixes and the tests.Verification
MallocScribble=1 MallocPreScribble=1, which makes reads of freed memory visible.result.cpp, 4 tests fail: the three merge tests and the split test.🤖 Generated with Claude Code