Avoid crashing if we try to read a png as a jpeg - closes #2903

This commit is contained in:
Dane Springmeyer 2015-06-11 14:02:34 -07:00
parent 6a3d63aa40
commit 84a0c49ec3
3 changed files with 20 additions and 2 deletions

View file

@ -206,8 +206,11 @@ void jpeg_reader<T>::attach_stream (j_decompress_ptr cinfo, input_stream* in)
}
template <typename T>
void jpeg_reader<T>::on_error(j_common_ptr /*cinfo*/)
void jpeg_reader<T>::on_error(j_common_ptr cinfo)
{
char buffer[JMSG_LENGTH_MAX];
(*cinfo->err->format_message)(cinfo, buffer);
throw image_reader_exception(std::string("JPEG Reader: libjpeg could not read image: ") + buffer);
}
template <typename T>

@ -1 +1 @@
Subproject commit bb25d5132c0245aa6188d04b9e22d191fb5aca7c
Subproject commit a6838f99a4c4be37989cea6718442cf4b53bd616

View file

@ -26,6 +26,21 @@ SECTION("readers") {
type = mapnik::type_from_filename(should_throw);
REQUIRE( type );
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
// actually a png so jpeg reader should throw
should_throw = "./test/data/images/landusepattern.jpg";
REQUIRE( mapnik::util::exists( should_throw ) );
type = mapnik::type_from_filename(should_throw);
REQUIRE( type );
try
{
std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type));
REQUIRE(false);
}
catch (std::exception const& ex)
{
REQUIRE( std::string(ex.what()) == std::string("JPEG Reader: libjpeg could not read image: Not a JPEG file: starts with 0x89") );
}
#endif
REQUIRE_THROWS(mapnik::image_rgba8 im(-10,-10)); // should throw rather than overflow