Skip to content

UBSAN: avoid int overflow in GenHFHadronMatcher#50891

Open
smuzaffar wants to merge 1 commit intocms-sw:masterfrom
smuzaffar:ubsan-GenHFHadronMatcher-int-overflow
Open

UBSAN: avoid int overflow in GenHFHadronMatcher#50891
smuzaffar wants to merge 1 commit intocms-sw:masterfrom
smuzaffar:ubsan-GenHFHadronMatcher-int-overflow

Conversation

@smuzaffar
Copy link
Copy Markdown
Contributor

UBSAN IBs show runtime errors like

src/PhysicsTools/JetMCAlgos/plugins/GenHFHadronMatcher.cc:982:77: runtime error: signed integer overflow: 100443 * 100443 cannot be represented in type 'int'

the code in question is https://github.com/cms-sw/cmssw/blob/master/PhysicsTools/JetMCAlgos/plugins/GenHFHadronMatcher.cc#L982 where ubsan complains about pdg_1 * pdg_2` overflowing int range. This PR proposes to change the logic and instead of multiplication just check the sign of these variables.

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented May 6, 2026

cms-bot internal usage

@smuzaffar
Copy link
Copy Markdown
Contributor Author

please test workflow 2500.3001 with #50882 for CMSSW_17_0_UBSAN_X

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented May 6, 2026

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented May 6, 2026

A new Pull Request was created by @smuzaffar for master.

It involves the following packages:

  • PhysicsTools/JetMCAlgos (analysis)

@tvami can you please review it and eventually sign? Thanks.
@AlexDeMoor, @Ming-Yan, @Senphy, @andrzejnovak, @castaned, @pavlo-kashko, @philippgadow this is something you requested to watch as well.
@ftenchini, @mandrenguyen, @sextonkennedy you are the release manager for this.

cms-bot commands are listed here

@smuzaffar
Copy link
Copy Markdown
Contributor Author

please test workflow 2500.3001

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented May 6, 2026

+1

Size: This PR adds an extra 28KB to repository
Summary: https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-2dfd16/53098/summary.html
COMMIT: 8ec6149
CMSSW: CMSSW_17_0_X_2026-05-05-2300/el8_amd64_gcc13
User test area: For local testing, you can use /cvmfs/cms-ci.cern.ch/week0/cms-sw/cmssw/50891/53098/install.sh to create a dev area with all the needed externals and cmssw changes.

Comparison Summary

Summary:

  • You potentially added 1 lines to the logs
  • Reco comparison results: 5 differences found in the comparisons
  • DQMHistoTests: Total files compared: 53
  • DQMHistoTests: Total histograms compared: 4187168
  • DQMHistoTests: Total failures: 6
  • DQMHistoTests: Total nulls: 0
  • DQMHistoTests: Total successes: 4187142
  • DQMHistoTests: Total skipped: 20
  • DQMHistoTests: Total Missing objects: 0
  • DQMHistoSizes: Histogram memory added: 0.0 KiB( 52 files compared)
  • Checked 227 log files, 197 edm output root files, 53 DQM output files
  • TriggerResults: no differences found

@cmsbuild
Copy link
Copy Markdown
Contributor

cmsbuild commented May 6, 2026

@smuzaffar
Copy link
Copy Markdown
Contributor Author

logs https://cmssdt.cern.ch/SDT/jenkins-artifacts/pull-request-integration/PR-2dfd16/53097/runTheMatrix-results/2500.3001_NANOmc150X/step2_NANOmc150X.log shows that there is no more int overflow runtime error

@cms-sw/analysis-l2 , can you please review this PR?

// Inverting the flavour if bb oscillation detected
if (isHadronPdgId(pdgId, pdg_1) && isHadronPdgId(pdgId, pdg_2) && pdg_1 * pdg_2 < 0) {
if (isHadronPdgId(pdgId, pdg_1) && isHadronPdgId(pdgId, pdg_2) &&
((pdg_1 < 0 && pdg_2 > 0) || (pdg_1 > 0 && pdg_2 < 0))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another option would be
std::signbit(pdg_1) xor std::signbit(pdg_2)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Dr15Jones , I think std::signbit(pdg_1) xor std::signbit(pdg_2) might not work if one of these variables hold 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed, but 0 is not a valid value for a PDG id (according to my internet search). Therefore no particle is ever supposed to have that value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah ok, in that case ((pdg_1 < 0) != (pdg_2 < 0)) should be enough but may be then we should add assert to make sure values are not zero

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants