diff --git a/src/generic/bmpsvg.cpp b/src/generic/bmpsvg.cpp index 37928bc89f..76f20dce4c 100644 --- a/src/generic/bmpsvg.cpp +++ b/src/generic/bmpsvg.cpp @@ -207,6 +207,15 @@ wxBitmapBundle wxBitmapBundle::FromSVG(char* data, const wxSize& sizeDef) if ( !svgImage ) return wxBitmapBundle(); + // Somewhat unexpectedly, a non-null but empty image is returned even if + // the data is not SVG at all, e.g. without this check creating a bundle + // from any random file with FromSVGFile() would "work". + if ( svgImage->width == 0 && svgImage->height == 0 && !svgImage->shapes ) + { + nsvgDelete(svgImage); + return wxBitmapBundle(); + } + return wxBitmapBundle(new wxBitmapBundleImplSVG(svgImage, sizeDef)); } diff --git a/tests/graphics/bmpbundle.cpp b/tests/graphics/bmpbundle.cpp index 176515624f..25002b29ef 100644 --- a/tests/graphics/bmpbundle.cpp +++ b/tests/graphics/bmpbundle.cpp @@ -140,9 +140,13 @@ TEST_CASE("BitmapBundle::FromSVG", "[bmpbundle][svg]") TEST_CASE("BitmapBundle::FromSVGFile", "[bmpbundle][svg][file]") { - wxBitmapBundle b = wxBitmapBundle::FromSVGFile("horse.svg", wxSize(20, 20)); + const wxSize size(20, 20); // completely arbitrary + + CHECK( !wxBitmapBundle::FromSVGFile("horse.bmp", size).IsOk() ); + + wxBitmapBundle b = wxBitmapBundle::FromSVGFile("horse.svg", size); REQUIRE( b.IsOk() ); - CHECK( b.GetDefaultSize() == wxSize(20, 20) ); + CHECK( b.GetDefaultSize() == size ); } #endif // wxHAS_SVG