Skip to content

Commit

Permalink
Fix memory corruption in reader initialization.
Browse files Browse the repository at this point in the history
For arrays, CreateProxy() can add to fValues which invalidates iterators.
Use stable, index-based iteration instead.
  • Loading branch information
Axel-Naumann committed Feb 1, 2018
1 parent e2c5e87 commit aecbe9b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tree/treeplayer/src/TTreeReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,14 @@ TTreeReader::EEntryStatus TTreeReader::SetEntryBase(Long64_t entry, Bool_t local
fMostRecentTreeNumber = fTree->GetTreeNumber();

if (!fProxiesSet) {
// Tell readers we now have a tree
for (std::deque<ROOT::Internal::TTreeReaderValueBase*>::const_iterator
i = fValues.begin(); i != fValues.end(); ++i) { // Iterator end changes when parameterized arrays are read
(*i)->CreateProxy();

if (!(*i)->GetProxy()){
// Tell readers we now have a tree.
// fValues gets insertions during this loop (when parameterized arrays are read),
// invalidating iterators. Use old-school counting instead.
for (size_t i = 0; i < fValues.size(); ++i) {
ROOT::Internal::TTreeReaderValueBase* reader = fValues[i];
reader->CreateProxy();

if (!reader->GetProxy()){
fEntryStatus = kEntryDictionaryError;
return fEntryStatus;
}
Expand Down

0 comments on commit aecbe9b

Please sign in to comment.