Skip to content

fix: protect against out of bounds access - #425

Open
madbaron wants to merge 7 commits into
key4hep:mainfrom
madbaron:guard_oparticles
Open

fix: protect against out of bounds access#425
madbaron wants to merge 7 commits into
key4hep:mainfrom
madbaron:guard_oparticles

Conversation

@madbaron

@madbaron madbaron commented Sep 1, 2026

Copy link
Copy Markdown
Member

This PR fixes a minor issue discovered in OverlayTiming when testing #413 at scale.
It would be good to merge this before #413, so that 413 would rebase cleanly

BEGINRELEASENOTES

  • Fix OverlayTiming indexing its output MCParticle collection with the -1 of an unset relation. Calorimeter contributions without an attached particle caused an out-of-bounds access that crashed when the contributions were written out.
  • Background hits and contributions whose particle is not part of the copied background particles now keep their relation unset instead of being silently attached to the first particle of the background event.

ENDRELEASENOTES

Comment thread k4FWCore/components/OverlayTiming.cpp Outdated
@jmcarcell

jmcarcell commented Sep 3, 2026

Copy link
Copy Markdown
Member

I think it would be good to change all the comparisons to test < 0 since there is also invalid = -2 (https://github.com/AIDASoft/podio/blob/master/include/podio/ObjectID.h#L22) that will cause exactly the same problem when the comparison fails with != 1.
I think changing all the accesses to .at instead of using the brackets is also not a bad idea, I don't think performance will be affected much and it would have caught these issues instead of creating another element in the maps.

@jmcarcell jmcarcell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These comments are for myself of which parts I am convinced that are a fix.

Comment thread k4FWCore/components/OverlayTiming.cpp Outdated
Comment thread k4FWCore/components/OverlayTiming.cpp
Comment thread k4FWCore/components/OverlayTiming.cpp
Comment thread k4FWCore/components/OverlayTiming.cpp Outdated
std::pair<float, float> OverlayTiming::define_time_windows(const std::string& collection_name) const {
try {
return {m_timeWindows.value().at(collection_name)[0], m_timeWindows.value().at(collection_name)[1]};
return {m_timeWindows.value().at(collection_name).at(0), m_timeWindows.value().at(collection_name).at(1)};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All brackets where changed to at, this is not needed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I've undone the relevant parts of my over-eager replace all (I was unsure of how to interpret your message).

If there's anything left, or anything that you'd like to move to at(), can you please mark it directly?

@madbaron

madbaron commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

@tmadlener @jmcarcell clang-tidy started to fail on things that seem unrelated to this PR. What do we do?

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.

3 participants