Merge pull request #2843 from mapnik/fix-webp-views
Fix potential crash when encoding webp via image_view
This commit is contained in:
commit
8d911d8c77
2 changed files with 34 additions and 6 deletions
|
@ -78,9 +78,11 @@ inline int import_image(T2 const& im_in,
|
|||
bool alpha)
|
||||
{
|
||||
image<typename T2::pixel> const& data = im_in.data();
|
||||
int stride = sizeof(typename T2::pixel_type) * im_in.width();
|
||||
if (data.width() == im_in.width() &&
|
||||
data.height() == im_in.height())
|
||||
std::size_t width = im_in.width();
|
||||
std::size_t height = im_in.height();
|
||||
int stride = sizeof(typename T2::pixel_type) * width;
|
||||
if (data.width() == width &&
|
||||
data.height() == height)
|
||||
{
|
||||
if (alpha)
|
||||
{
|
||||
|
@ -98,12 +100,12 @@ inline int import_image(T2 const& im_in,
|
|||
else
|
||||
{
|
||||
// need to copy: https://github.com/mapnik/mapnik/issues/2024
|
||||
image_rgba8 im(im_in.width(),im_in.height());
|
||||
for (unsigned y = 0; y < im_in.height(); ++y)
|
||||
image_rgba8 im(width,height);
|
||||
for (unsigned y = 0; y < height; ++y)
|
||||
{
|
||||
typename T2::pixel_type const * row_from = im_in.get_row(y);
|
||||
image_rgba8::pixel_type * row_to = im.get_row(y);
|
||||
std::copy(row_from, row_from + stride, row_to);
|
||||
std::copy(row_from, row_from + width, row_to);
|
||||
}
|
||||
if (alpha)
|
||||
{
|
||||
|
|
26
test/unit/imaging/webp_io.cpp
Normal file
26
test/unit/imaging/webp_io.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
|
||||
#if defined(HAVE_WEBP)
|
||||
|
||||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/image_util.hpp>
|
||||
#include <mapnik/image_view_any.hpp>
|
||||
#include <mapnik/webp_io.hpp>
|
||||
|
||||
TEST_CASE("webp io") {
|
||||
|
||||
SECTION("does not crash accessing view") {
|
||||
std::stringstream s;
|
||||
mapnik::image_rgba8 im(1024,1024);
|
||||
mapnik::image_view_rgba8 view(512,512,1024,1024,im);
|
||||
WebPConfig config;
|
||||
if (!WebPConfigInit(&config))
|
||||
{
|
||||
throw std::runtime_error("version mismatch");
|
||||
}
|
||||
save_as_webp(s,view,config,true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue