Skip to content

Commit

Permalink
Fix use after free in ADIOS1IOHandler (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel authored Mar 13, 2022
1 parent eec3f06 commit 272b137
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion include/openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ class CommonADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
m_openWriteFileHandles;
std::unordered_map<std::shared_ptr<std::string>, ADIOS_FILE *>
m_openReadFileHandles;
std::unordered_map<ADIOS_FILE *, std::vector<ADIOS_SELECTION *> >
struct ScheduledRead
{
ADIOS_SELECTION *selection;
std::shared_ptr<void> data; // needed to avoid early freeing
};
std::unordered_map<ADIOS_FILE *, std::vector<ScheduledRead> >
m_scheduledReads;
std::unordered_map<int64_t, std::unordered_map<std::string, Attribute> >
m_attributeWrites;
Expand Down
2 changes: 1 addition & 1 deletion src/IO/ADIOS/ADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ std::future<void> ADIOS1IOHandlerImpl::flush()
"dataset reading");

for (auto &sel : file.second)
adios_selection_delete(sel);
adios_selection_delete(sel.selection);
}
m_scheduledReads.clear();

Expand Down
4 changes: 2 additions & 2 deletions src/IO/ADIOS/CommonADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::closeFile(
"dataset reading");

for (auto &sel : scheduled->second)
adios_selection_delete(sel);
adios_selection_delete(sel.selection);
m_scheduledReads.erase(scheduled);
}
close(handle_read->second);
Expand Down Expand Up @@ -1183,7 +1183,7 @@ void CommonADIOS1IOHandlerImpl<ChildClass>::readDataset(
"[ADIOS1] Internal error: Failed to schedule ADIOS read during dataset "
"reading");

m_scheduledReads[f].push_back(sel);
m_scheduledReads[f].push_back({sel, parameters.data});
}

template <typename ChildClass>
Expand Down
2 changes: 1 addition & 1 deletion src/IO/ADIOS/ParallelADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ std::future<void> ParallelADIOS1IOHandlerImpl::flush()
"dataset reading");

for (auto &sel : file.second)
adios_selection_delete(sel);
adios_selection_delete(sel.selection);
}
m_scheduledReads.clear();

Expand Down

0 comments on commit 272b137

Please sign in to comment.