Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f830e37

Browse files
committed
Fix out-of-memory errors leading to segfaults
svn path=/branches/v0_98_5_maint/; revision=7245
1 parent 2bc67ef commit f830e37

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/_path.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ Py::Object _path_module::clip_path_to_rect(const Py::Tuple &args)
882882
size_t size = p->size();
883883
dims[0] = p->size();
884884
PyArrayObject* pyarray = (PyArrayObject*)PyArray_SimpleNew(2, dims, PyArray_DOUBLE);
885+
if (pyarray == NULL) {
886+
throw Py::MemoryError("Could not allocate result array");
887+
}
885888
for (size_t i = 0; i < size; ++i)
886889
{
887890
((double *)pyarray->data)[2*i] = (*p)[i].x;
@@ -951,6 +954,9 @@ Py::Object _path_module::affine_transform(const Py::Tuple& args)
951954

952955
result = (PyArrayObject*)PyArray_SimpleNew
953956
(PyArray_NDIM(vertices), PyArray_DIMS(vertices), PyArray_DOUBLE);
957+
if (result == NULL) {
958+
throw Py::MemoryError("Could not allocate memory for path");
959+
}
954960
if (PyArray_NDIM(vertices) == 2)
955961
{
956962
size_t n = PyArray_DIM(vertices, 0);

src/_png.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ _png_module::read_png(const Py::Tuple& args) {
266266
double max_value = (1 << ((bit_depth < 8) ? 8 : bit_depth)) - 1;
267267
PyArrayObject *A = (PyArrayObject *) PyArray_SimpleNew(num_dims, dimensions, PyArray_FLOAT);
268268

269+
if (A == NULL) {
270+
throw Py::MemoryError("Could not allocate image array");
271+
}
272+
269273
for (png_uint_32 y = 0; y < height; y++) {
270274
png_byte* row = row_pointers[y];
271275
for (png_uint_32 x = 0; x < width; x++) {

0 commit comments

Comments
 (0)