Skip to content

Commit 3ca461e

Browse files
committed
Merge pull request #3324 from mdboom/backend-agg-crash
BUG : fixes memory corruption issues with zero-size rasterized artists Fix #3304.
2 parents c04a828 + 5b0e0d8 commit 3ca461e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/_backend_agg.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
24082408
data = PyBytes_FromStringAndSize(NULL, newsize);
24092409
if (data == NULL)
24102410
{
2411-
throw Py::MemoryError("RendererAgg::tostring_minimized could not allocate memory");
2411+
throw Py::MemoryError("RendererAgg::tostring_rgba_minimized could not allocate memory");
24122412
}
24132413
dst = (unsigned int *)PyBytes_AsString(data);
24142414

@@ -2420,6 +2420,12 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
24202420
*dst = src[y * width + x];
24212421
}
24222422
}
2423+
} else {
2424+
data = PyBytes_FromStringAndSize(NULL, 0);
2425+
if (data == NULL)
2426+
{
2427+
throw Py::MemoryError("RendererAgg::tostring_rgba_minimized could not allocate memory");
2428+
}
24232429
}
24242430

24252431
Py::Tuple bounds(4);
@@ -2429,8 +2435,7 @@ RendererAgg::tostring_rgba_minimized(const Py::Tuple& args)
24292435
bounds[3] = Py::Int(newheight);
24302436

24312437
Py::Tuple result(2);
2432-
result[0] = Py::Object(data, false);
2433-
Py_DECREF(data);
2438+
result[0] = Py::Object(data, true);
24342439
result[1] = bounds;
24352440

24362441
return result;

0 commit comments

Comments
 (0)