Skip to content

Commit 37d5e29

Browse files
committed
Fix use after free in ADIOS1IOHandler
1 parent fe9a67e commit 37d5e29

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

include/openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ namespace openPMD
8888
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
8989
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
9090
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
91-
std::unordered_map< ADIOS_FILE*, std::vector< ADIOS_SELECTION* > > m_scheduledReads;
91+
struct ScheduledRead
92+
{
93+
ADIOS_SELECTION* selection;
94+
std::shared_ptr< void > data; // needed to avoid early freeing
95+
};
96+
std::unordered_map< ADIOS_FILE*, std::vector< ScheduledRead > > m_scheduledReads;
9297
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
9398
// config options
9499
std::string m_defaultTransform;

src/IO/ADIOS/ADIOS1IOHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ ADIOS1IOHandlerImpl::flush()
212212
VERIFY(status == err_no_error, "[ADIOS1] Internal error: Failed to perform ADIOS reads during dataset reading");
213213

214214
for( auto& sel : file.second )
215-
adios_selection_delete(sel);
215+
adios_selection_delete(sel.selection);
216216
}
217217
m_scheduledReads.clear();
218218

src/IO/ADIOS/CommonADIOS1IOHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ CommonADIOS1IOHandlerImpl< ChildClass >::closeFile(
701701
"dataset reading" );
702702

703703
for( auto & sel : scheduled->second )
704-
adios_selection_delete( sel );
704+
adios_selection_delete( sel.selection );
705705
m_scheduledReads.erase( scheduled );
706706
}
707707
close( handle_read->second );
@@ -1129,7 +1129,7 @@ CommonADIOS1IOHandlerImpl< ChildClass >::readDataset(Writable* writable,
11291129
VERIFY(status == err_no_error, "[ADIOS1] Internal error: Failed to schedule ADIOS read during dataset reading");
11301130
VERIFY(adios_errno == err_no_error, "[ADIOS1] Internal error: Failed to schedule ADIOS read during dataset reading");
11311131

1132-
m_scheduledReads[f].push_back(sel);
1132+
m_scheduledReads[f].push_back({sel, parameters.data});
11331133
}
11341134

11351135
template< typename ChildClass >

src/IO/ADIOS/ParallelADIOS1IOHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ParallelADIOS1IOHandlerImpl::flush()
232232
VERIFY(status == err_no_error, "[ADIOS1] Internal error: Failed to perform ADIOS reads during dataset reading");
233233

234234
for( auto& sel : file.second )
235-
adios_selection_delete(sel);
235+
adios_selection_delete(sel.selection);
236236
}
237237
m_scheduledReads.clear();
238238

0 commit comments

Comments
 (0)