Repository navigation
fix: segfault in FeatureLinkerUnlabeledKD with charge_merging=Any - #8944
Conversation
When charge_merging="Any", the KD candidate filter allows features with any charge into the pool. However, the FeatureDistance functor (which ranks candidates) had ignore_charge=false, causing it to return infinity for non-zero charge mismatches. If all candidates from a map had a different non-zero charge than the center, best_index stayed at SIZE_MAX, leading to an out-of-bounds access in addConsensusFeature_(). Fix: set ignore_charge=true on FeatureDistance when charge_merging="Any" so the distance functor does not contradict the candidate filter. Closes #8927 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughA conditional was added in FeatureGroupingAlgorithmKD to set the distance parameter Changes
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openms/source/ANALYSIS/MAPMATCHING/FeatureGroupingAlgorithmKD.cpp`:
- Around line 132-137: When link:adduct_merging is "Any" the distance functor
must not reject adduct-mismatched pairs; update the same block that checks
param_.getValue("link:charge_merging") to also check
param_.getValue("link:adduct_merging") and call
distance_params.setValue("ignore_adduct", "true") when it equals "Any" (this
mirrors the existing ignore_charge behavior used with FeatureDistance and
prevents best_index from remaining max and being dereferenced); modify the code
near where distance_params is configured (the block that touches ignore_charge)
so both ignore_charge and ignore_adduct are set appropriately.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55849e72-5787-4266-8ac2-319f75eb8295
📒 Files selected for processing (1)
src/openms/source/ANALYSIS/MAPMATCHING/FeatureGroupingAlgorithmKD.cpp
| // charge_merging="Any" allows all charge states into the candidate pool, | ||
| // so FeatureDistance must not reject charge-mismatched pairs (segfault: #8927) | ||
| if (param_.getValue("link:charge_merging").toString() == "Any") | ||
| { | ||
| distance_params.setValue("ignore_charge", "true"); | ||
| } |
There was a problem hiding this comment.
Also set ignore_adduct for link:adduct_merging="Any" to avoid the same crash pattern.
The charge-side fix is correct, but the adduct-side mismatch remains: merge_adduct == "Any" keeps all candidates (Line 432), while FeatureDistance still rejects adduct-mismatched pairs with infinity when ignore_adduct is false (FeatureDistance.cpp:124-205). If a map contributes only such candidates, best_index can stay numeric_limits<Size>::max() (Line 453) and later be dereferenced.
💡 Proposed fix
@@
if (param_.getValue("link:charge_merging").toString() == "Any")
{
distance_params.setValue("ignore_charge", "true");
}
+ if (param_.getValue("link:adduct_merging").toString() == "Any")
+ {
+ distance_params.setValue("ignore_adduct", "true");
+ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/openms/source/ANALYSIS/MAPMATCHING/FeatureGroupingAlgorithmKD.cpp` around
lines 132 - 137, When link:adduct_merging is "Any" the distance functor must not
reject adduct-mismatched pairs; update the same block that checks
param_.getValue("link:charge_merging") to also check
param_.getValue("link:adduct_merging") and call
distance_params.setValue("ignore_adduct", "true") when it equals "Any" (this
mirrors the existing ignore_charge behavior used with FeatureDistance and
prevents best_index from remaining max and being dereferenced); modify the code
near where distance_params is configured (the block that touches ignore_charge)
so both ignore_charge and ignore_adduct are set appropriately.
Two minimal featureXML inputs with different non-zero charges (2 vs 3) at similar RT/mz. Without the fix, this segfaults because FeatureDistance returns infinity for all candidates, leaving best_index at SIZE_MAX. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
| // charge_merging="Any" allows all charge states into the candidate pool, | ||
| // so FeatureDistance must not reject charge-mismatched pairs (segfault: #8927) | ||
| if (param_.getValue("link:charge_merging").toString() == "Any") | ||
| { | ||
| distance_params.setValue("ignore_charge", "true"); |
There was a problem hiding this comment.
while this limits the number of cases where a segfault occurs, it probably does not prevent all possible cases.
Should the full fix add a test for infinity, or if any features could be matched at all?! (not sure what the underlying actual segfaulting call is).
There was a problem hiding this comment.
I think it segfaults if there are just different charges. e.g. f1 has z=2 and f2 has z=3
previously it got infinity because distance did not ignore charge
|
will merge as it is definitely more correct now and I don't have time to investigate further |
Add missing changelog entries for: - BREAKING: Qt string API removal from String/DataValue (#8940) - BREAKING: Qt6::Core removed from libOpenMS PUBLIC CMake deps (#8965) - BREAKING: Transitive includes trimmed from KERNEL/METADATA headers (#8946) - Fix: segfault in FeatureLinkerUnlabeledKD with charge_merging=Any (#8944) Co-authored-by: Copilot <[email protected]>
Add missing changelog entries for: - BREAKING: Qt string API removal from String/DataValue (#8940) - BREAKING: Qt6::Core removed from libOpenMS PUBLIC CMake deps (#8965) - BREAKING: Transitive includes trimmed from KERNEL/METADATA headers (#8946) - Fix: segfault in FeatureLinkerUnlabeledKD with charge_merging=Any (#8944) Co-authored-by: GitHub Copilot <[email protected]> Co-authored-by: Copilot <[email protected]>
Summary
-algorithm:link:charge_merging Anyin FeatureLinkerUnlabeledKDFeatureDistancefunctor rejected charge-mismatched pairs that the KD candidate filter intentionally allowed, leavingbest_indexatSIZE_MAX→ out-of-bounds vector accessRoot Cause
The KD algorithm has two stages: a candidate filter (lines 369-387) that decides which features enter the pool, and a distance functor (
FeatureDistance) that ranks them. Whencharge_merging="Any", the candidate filter allows all charge states through. ButFeatureDistancehadignore_charge=false(hardcoded default — the param was removed from the KD algorithm's parameter set at construction). This caused it to returninfinityfor non-zero charge mismatches (e.g., charge 2 vs charge 3).If all candidates from a given map had a different non-zero charge than the center feature, every distance was
infinity,best_indexstayed atnumeric_limits<Size>::max(), andkd_data.feature(SIZE_MAX)segfaulted.Fix
Set
ignore_charge=trueonFeatureDistancewhencharge_merging="Any". This is correct because the KD filter already handles charge filtering —FeatureDistanceshould only compute distances for the candidates that passed.With_charge_zerois not affected becauseFeatureDistance's default charge logic (allow pairing when one side is charge 0) exactly matches what the KD filter allows through.Test plan
charge_merging=Any)charge_merging=Anytests is identical (no behavior change for existing test data)Closes #8927
🤖 Generated with Claude Code
Summary by CodeRabbit