Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ADIOS1 String Attributes #269

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
os: osx
language: generic
env:
- USE_MPI=OFF USE_PYTHON=ON USE_HDF5=ON USE_ADIOS1=OFF USE_ADIOS2=OFF USE_SAMPLES=ON
- USE_MPI=OFF USE_PYTHON=ON USE_HDF5=ON USE_ADIOS1=ON USE_ADIOS2=OFF USE_SAMPLES=ON
compiler: clang
before_install:
- COMPILERSPEC="%[email protected]"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Bug Fixes
- recursive directory creation with existing base #261
- ``FindADIOS.cmake``: reset on multiple calls #263
- ``SerialIOTest``: remove variable shadowing #262
- ADIOS1: memory violation in string attribute writes #269

Other
"""""
Expand Down
16 changes: 8 additions & 8 deletions src/IO/ADIOS/ADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,

Attribute att = Attribute(parameters.resource);

int nelems;
int nelems = 0;
switch( parameters.dtype )
{
using DT = Datatype;
Expand Down Expand Up @@ -840,9 +840,9 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,
}
case DT::STRING:
{
using uptr = std::unique_ptr< void, std::function< void(void*) > >;
values = uptr(const_cast< char* >(att.get< std::string >().c_str()),
[](void*){ });
auto const & v = att.get< std::string >();
values = auxiliary::allocatePtr(Datatype::CHAR, v.length() + 1u);
strcpy((char*)values.get(), v.c_str());
break;
}
case DT::VEC_CHAR:
Expand Down Expand Up @@ -977,7 +977,7 @@ ADIOS1IOHandlerImpl::writeAttribute(Writable* writable,
"",
getBP1DataType(parameters.dtype),
nelems,
values.get());
values.get()); // Invalid read of size 1 (could be in ADIOS itself?)
Copy link
Member Author

Choose a reason for hiding this comment

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

in strlen() in adios_get_type_size (adios_bp_v1.c:2415) in adios_common_define_attribute_byvalue (adios_internals.c:1109) in adios_define_attribute_byvalue (adios.c:442) in openPMD::ADIOS1IOHandlerImpl::writeAttribute on string value: serial_fileBased_write%T

Copy link
Member Author

Choose a reason for hiding this comment

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

we already pass the invalid c-string.

strlen((const char*)values.get()) is an invalid read of size 1

Copy link
Member

Choose a reason for hiding this comment

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

Very likely because of #269 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

ah dang, just found it as well :)
yes, we can not defer/forward the pointer we get there :)

VERIFY(status == err_no_error, "Internal error: Failed to define ADIOS attribute by value");

if( parameters.dtype == Datatype::VEC_STRING )
Expand Down Expand Up @@ -1053,9 +1053,9 @@ ADIOS1IOHandlerImpl::readAttribute(Writable* writable,
attrname += "/";
attrname += parameters.name;

ADIOS_DATATYPES datatype;
int size;
void* data;
ADIOS_DATATYPES datatype = adios_unknown;
int size = 0;
void* data = nullptr;

int status;
status = adios_get_attr(f,
Expand Down