From 7944fb8704d73da217dbd6fefa494a26661cf743 Mon Sep 17 00:00:00 2001 From: Daniel Nachbaur Date: Wed, 6 Jul 2016 11:46:24 +0200 Subject: [PATCH] Fix GID out-of-bounds handling for MVD3 in brain::Circuit --- .gitsubprojects | 2 +- CMakeLists.txt | 2 +- brain/circuit.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++----------- brion/circuit.cpp | 9 ++++--- doc/Changelog.md | 5 ++++ tests/circuit.cpp | 28 ++++++++++++++++---- 6 files changed, 96 insertions(+), 26 deletions(-) diff --git a/.gitsubprojects b/.gitsubprojects index d50f3ea..e7f7910 100644 --- a/.gitsubprojects +++ b/.gitsubprojects @@ -1,5 +1,5 @@ # -*- mode: cmake -*- git_subproject(Servus https://github.com/HBPVIS/Servus.git 134b674) -git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git 440fded) +git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git d596d7b) git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git 10d93e6) git_subproject(MVDTool https://github.com/BlueBrain/MVDTool.git 03d8138) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae44984..e905bd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ # cmake_minimum_required(VERSION 3.1 FATAL_ERROR) -project(Brion VERSION 1.8.0) +project(Brion VERSION 1.9.0) set(Brion_VERSION_ABI 7) list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake diff --git a/brain/circuit.cpp b/brain/circuit.cpp index 3e340ed..39fe466 100644 --- a/brain/circuit.cpp +++ b/brain/circuit.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -288,18 +289,36 @@ class MVD3 : public Circuit::Impl { Vector3fs results( gids.size( )); const ::MVD3::Range& range = getRange( gids ); - const ::MVD3::Positions& positions = _circuit.getPositions( range ); - assign( range, gids, positions, results, toVector3f ); - return results; + try + { + brion::detail::SilenceHDF5 silence; + const ::MVD3::Positions& positions = _circuit.getPositions( range ); + assign( range, gids, positions, results, toVector3f ); + return results; + } + catch( const HighFive::Exception& e ) + { + LBTHROW( std::runtime_error( "Exception in getPositions(): " + + std::string( e.what( )))); + } } size_ts getMTypes( const GIDSet& gids ) const final { size_ts results( gids.size( )); const ::MVD3::Range& range = getRange( gids ); - const size_ts& mtypes = _circuit.getIndexMtypes( range ); - assign( range, gids, mtypes, results, nop ); - return results; + try + { + brion::detail::SilenceHDF5 silence; + const size_ts& mtypes = _circuit.getIndexMtypes( range ); + assign( range, gids, mtypes, results, nop ); + return results; + } + catch( const HighFive::Exception& e ) + { + LBTHROW( std::runtime_error( "Exception in getMTypes(): " + + std::string( e.what( )))); + } } Strings getMorphologyNames() const final @@ -311,9 +330,18 @@ class MVD3 : public Circuit::Impl { size_ts results( gids.size( )); const ::MVD3::Range& range = getRange( gids ); - const size_ts& etypes = _circuit.getIndexEtypes( range ); - assign( range, gids, etypes, results, nop ); - return results; + try + { + brion::detail::SilenceHDF5 silence; + const size_ts& etypes = _circuit.getIndexEtypes( range ); + assign( range, gids, etypes, results, nop ); + return results; + } + catch( const HighFive::Exception& e ) + { + LBTHROW( std::runtime_error( "Exception in getETypes(): " + + std::string( e.what( )))); + } } Strings getElectrophysiologyNames() const final @@ -325,18 +353,36 @@ class MVD3 : public Circuit::Impl { Quaternionfs results( gids.size( )); const ::MVD3::Range& range = getRange( gids ); - const ::MVD3::Rotations& rotations = _circuit.getRotations( range ); - assign( range, gids, rotations, results, toQuaternion ); - return results; + try + { + brion::detail::SilenceHDF5 silence; + const ::MVD3::Rotations& rotations = _circuit.getRotations( range ); + assign( range, gids, rotations, results, toQuaternion ); + return results; + } + catch( const HighFive::Exception& e ) + { + LBTHROW( std::runtime_error( "Exception in getRotations(): " + + std::string( e.what( )))); + } } Strings getMorphologyNames( const GIDSet& gids ) const final { Strings results( gids.size( )); const ::MVD3::Range& range = getRange( gids ); - const Strings& morphos = _circuit.getMorphologies( range ); - assign( range, gids, morphos, results, toString ); - return results; + try + { + brion::detail::SilenceHDF5 silence; + const Strings& morphos = _circuit.getMorphologies( range ); + assign( range, gids, morphos, results, toString ); + return results; + } + catch( const HighFive::Exception& e ) + { + LBTHROW( std::runtime_error( "Exception in getMorphologyNames(): " + + std::string( e.what( )))); + } } private: diff --git a/brion/circuit.cpp b/brion/circuit.cpp index da7e63a..d9af823 100644 --- a/brion/circuit.cpp +++ b/brion/circuit.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -52,8 +53,8 @@ class Circuit::Impl fs::path path = source; const std::string ext = fs::extension( path ); if( ext != ".mvd" && ext != ".mvd2" ) - throw std::runtime_error( "Expecting mvd file format for circuit " - "file " + source ); + LBTHROW( std::runtime_error( "Expecting mvd file format for " + " circuit file " + source )); typedef stde::hash_map< std::string, Section > LookUp; LookUp sections; @@ -97,13 +98,13 @@ class Circuit::Impl std::vector indices; indices.reserve( gids.size( )); - BOOST_FOREACH( const uint32_t gid, gids) + BOOST_FOREACH( const uint32_t gid, gids ) { if ( gid > neurons.size( )) { std::stringstream msg; msg << "Cell GID out of range: " << gid; - throw std::runtime_error( msg.str().c_str( )); + LBTHROW( std::runtime_error( msg.str().c_str( ))); } indices.push_back( gid - 1 ); } diff --git a/doc/Changelog.md b/doc/Changelog.md index 31f63ca..f71682f 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -1,6 +1,11 @@ Changelog {#Changelog} ========= +# Release 1.9.0 (git master) + +* [81](https://github.com/BlueBrain/Brion/pull/81): + Fix GID out-of-bounds handling for MVD3 in brain::Circuit + # Release 1.8.0 (30-Jun-2016) * [77](https://github.com/BlueBrain/Brion/pull/77): diff --git a/tests/circuit.cpp b/tests/circuit.cpp index 6405982..acbae91 100644 --- a/tests/circuit.cpp +++ b/tests/circuit.cpp @@ -34,6 +34,8 @@ #define BOOST_TEST_MODULE Circuit #include +#include +#include #include #include @@ -228,15 +230,31 @@ void _checkMorphology( const brain::neuron::Morphology& morphology, } } -BOOST_AUTO_TEST_CASE( load_bad_morphologies ) +BOOST_AUTO_TEST_CASE( test_gid_out_of_range ) { - const brain::Circuit circuit( (brion::URI( bbp::test::getBlueconfig( )))); + typedef boost::shared_ptr< const brain::Circuit > CircuitPtr; + std::vector< CircuitPtr > circuits; + circuits.push_back( CircuitPtr( new brain::Circuit( + brion::URI( BBP_TEST_BLUECONFIG )))); +#ifdef BRAIN_USE_MVD3 + circuits.push_back( CircuitPtr( new brain::Circuit( + brion::URI( BBP_TEST_BLUECONFIG3 )))); +#endif brion::GIDSet gids; gids.insert( 10000000 ); - BOOST_CHECK_THROW( - circuit.loadMorphologies( gids, brain::Circuit::COORDINATES_LOCAL ), - std::runtime_error ); + BOOST_FOREACH( const CircuitPtr& circuit, circuits ) + { + BOOST_CHECK_THROW( circuit->getPositions( gids ), std::runtime_error ); + BOOST_CHECK_THROW( circuit->getMorphologyTypes( gids ), + std::runtime_error ); + BOOST_CHECK_THROW( circuit->getElectrophysiologyTypes( gids ), + std::runtime_error ); + BOOST_CHECK_THROW( circuit->getRotations( gids ), std::runtime_error ); + BOOST_CHECK_THROW( + circuit->loadMorphologies( gids, brain::Circuit::COORDINATES_LOCAL), + std::runtime_error ); + } } BOOST_AUTO_TEST_CASE( load_local_morphologies )