diff --git a/src/jpeg_reader.cpp b/src/jpeg_reader.cpp index 213469403..e6db1d527 100644 --- a/src/jpeg_reader.cpp +++ b/src/jpeg_reader.cpp @@ -206,8 +206,11 @@ void jpeg_reader::attach_stream (j_decompress_ptr cinfo, input_stream* in) } template -void jpeg_reader::on_error(j_common_ptr /*cinfo*/) +void jpeg_reader::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 diff --git a/test/data b/test/data index bb25d5132..a6838f99a 160000 --- a/test/data +++ b/test/data @@ -1 +1 @@ -Subproject commit bb25d5132c0245aa6188d04b9e22d191fb5aca7c +Subproject commit a6838f99a4c4be37989cea6718442cf4b53bd616 diff --git a/test/unit/imaging/image_io_test.cpp b/test/unit/imaging/image_io_test.cpp index 8772ef3cd..d0a984d7d 100644 --- a/test/unit/imaging/image_io_test.cpp +++ b/test/unit/imaging/image_io_test.cpp @@ -26,6 +26,21 @@ SECTION("readers") { type = mapnik::type_from_filename(should_throw); REQUIRE( type ); REQUIRE_THROWS(std::unique_ptr 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 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 0x50") ); + } #endif REQUIRE_THROWS(mapnik::image_rgba8 im(-10,-10)); // should throw rather than overflow