acd: uninitialised read of bestPerm in enumerate_iset_combinations - #539
Open
marcelwa wants to merge 1 commit into
Open
acd: uninitialised read of bestPerm in enumerate_iset_combinations#539marcelwa wants to merge 1 commit into
marcelwa wants to merge 1 commit into
Conversation
…ombinations bestPerm is only written inside the 'cost < best_cost' branch. When no combination beats the initial best_cost -- which happens for an infeasible free-set size -- the array is never written, yet the tail of the function still evaluates permutations[bestPerm[i]]. That reads uninitialised stack and then uses the value to index permutations[], so it is an out-of-bounds read as well. Upstream results are unaffected in practice because the caller discards the permutation on that path, but it is undefined behaviour and it becomes a hard segfault as soon as the stack layout changes -- adding two members to the decomposer object was enough to trigger it reliably. Seeding the identity permutation in the existing initialisation loop is sufficient and costs nothing.
This was referenced Aug 8, 2026
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.
The defect
In
src/map/if/acd/ac_decomposition.hpp,enumerate_iset_combinationsdeclaresand writes
bestPermonly inside thecost < best_costbranch:When no combination beats the initial
best_cost— which happens for an infeasible free-set size —bestPermis never written. The tail of the function nevertheless evaluates it:That is a read of uninitialised stack, and because the value is then used as an index into
permutations[], it is an out-of-bounds read as well.Impact
Benign in upstream today: the caller discards that permutation on the infeasible path, so results are unaffected. But it is undefined behaviour, and it becomes a reliable segfault the moment the stack layout shifts — adding two members to the decomposer object was enough to reproduce it consistently while instrumenting the pass.
The fix
Seed the identity permutation in the initialisation loop that already runs immediately above. Five lines, no behavioural change on any path that was previously well-defined, and no measurable cost.
Testing
Built clean, and
if -K 10 -Z 6still maps correctly (cavlc:nd = 121, lev = 4). Found while measuring ACD's column-multiplicity headroom across the EPFL suite; the pass was exercised over 180+ mapping jobs on this branch with no change in output.