Skip to content

Commit

Permalink
Fix crash when reading PNG files with an invalid header (#385)
Browse files Browse the repository at this point in the history
Removed assertions, as they prevent the expected
`std::ios_base::failure` exception to be caught in such a case.
  • Loading branch information
macmade authored and mloskot committed Aug 26, 2019
1 parent 124f621 commit bd00f91
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions include/boost/gil/extension/io/png/detail/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ struct png_struct_info_wrapper
{
if( png_ptr )
{
BOOST_ASSERT(png_ptr->_struct && png_ptr->_info);

png_destroy_read_struct( &png_ptr->_struct
, &png_ptr->_info
, nullptr
);
if( png_ptr->_struct && png_ptr->_info )
{
png_destroy_read_struct( &png_ptr->_struct
, &png_ptr->_info
, nullptr
);
}

delete png_ptr;
png_ptr = nullptr;
Expand All @@ -78,11 +79,12 @@ struct png_struct_info_wrapper
{
if( png_ptr )
{
BOOST_ASSERT(png_ptr->_struct && png_ptr->_info);

png_destroy_write_struct( &png_ptr->_struct
, &png_ptr->_info
);
if( png_ptr->_struct && png_ptr->_info )
{
png_destroy_write_struct( &png_ptr->_struct
, &png_ptr->_info
);
}

delete png_ptr;
png_ptr = nullptr;
Expand Down

0 comments on commit bd00f91

Please sign in to comment.