mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Handle failure from PyDict_New or PyList_New
This commit is contained in:
		
							parent
							
								
									cdf5fd439c
								
							
						
					
					
						commit
						929dbba834
					
				| 
						 | 
					@ -1249,6 +1249,9 @@ _histogram(ImagingObject *self, PyObject *args) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Build an integer list containing the histogram */
 | 
					    /* Build an integer list containing the histogram */
 | 
				
			||||||
    list = PyList_New(h->bands * 256);
 | 
					    list = PyList_New(h->bands * 256);
 | 
				
			||||||
 | 
					    if (list == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for (i = 0; i < h->bands * 256; i++) {
 | 
					    for (i = 0; i < h->bands * 256; i++) {
 | 
				
			||||||
        PyObject *item;
 | 
					        PyObject *item;
 | 
				
			||||||
        item = PyLong_FromLong(h->histogram[i]);
 | 
					        item = PyLong_FromLong(h->histogram[i]);
 | 
				
			||||||
| 
						 | 
					@ -2154,6 +2157,9 @@ _getcolors(ImagingObject *self, PyObject *args) {
 | 
				
			||||||
        Py_INCREF(out);
 | 
					        Py_INCREF(out);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        out = PyList_New(colors);
 | 
					        out = PyList_New(colors);
 | 
				
			||||||
 | 
					        if (out == NULL) {
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        for (i = 0; i < colors; i++) {
 | 
					        for (i = 0; i < colors; i++) {
 | 
				
			||||||
            ImagingColorItem *v = &items[i];
 | 
					            ImagingColorItem *v = &items[i];
 | 
				
			||||||
            PyObject *item = Py_BuildValue(
 | 
					            PyObject *item = Py_BuildValue(
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1082,6 +1082,9 @@ font_getvarnames(FontObject *self) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    num_namedstyles = master->num_namedstyles;
 | 
					    num_namedstyles = master->num_namedstyles;
 | 
				
			||||||
    list_names = PyList_New(num_namedstyles);
 | 
					    list_names = PyList_New(num_namedstyles);
 | 
				
			||||||
 | 
					    if (list_names == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    name_count = FT_Get_Sfnt_Name_Count(self->face);
 | 
					    name_count = FT_Get_Sfnt_Name_Count(self->face);
 | 
				
			||||||
    for (i = 0; i < name_count; i++) {
 | 
					    for (i = 0; i < name_count; i++) {
 | 
				
			||||||
| 
						 | 
					@ -1125,10 +1128,16 @@ font_getvaraxes(FontObject *self) {
 | 
				
			||||||
    name_count = FT_Get_Sfnt_Name_Count(self->face);
 | 
					    name_count = FT_Get_Sfnt_Name_Count(self->face);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    list_axes = PyList_New(num_axis);
 | 
					    list_axes = PyList_New(num_axis);
 | 
				
			||||||
 | 
					    if (list_axes == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    for (i = 0; i < num_axis; i++) {
 | 
					    for (i = 0; i < num_axis; i++) {
 | 
				
			||||||
        axis = master->axis[i];
 | 
					        axis = master->axis[i];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        list_axis = PyDict_New();
 | 
					        list_axis = PyDict_New();
 | 
				
			||||||
 | 
					        if (list_axis == NULL) {
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        PyDict_SetItemString(
 | 
					        PyDict_SetItemString(
 | 
				
			||||||
            list_axis, "minimum", PyLong_FromLong(axis.minimum / 65536));
 | 
					            list_axis, "minimum", PyLong_FromLong(axis.minimum / 65536));
 | 
				
			||||||
        PyDict_SetItemString(list_axis, "default", PyLong_FromLong(axis.def / 65536));
 | 
					        PyDict_SetItemString(list_axis, "default", PyLong_FromLong(axis.def / 65536));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -136,6 +136,9 @@ match(PyObject *self, PyObject *args) {
 | 
				
			||||||
    int row_idx, col_idx;
 | 
					    int row_idx, col_idx;
 | 
				
			||||||
    UINT8 **inrows;
 | 
					    UINT8 **inrows;
 | 
				
			||||||
    PyObject *ret = PyList_New(0);
 | 
					    PyObject *ret = PyList_New(0);
 | 
				
			||||||
 | 
					    if (ret == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "On", &py_lut, &i0)) {
 | 
					    if (!PyArg_ParseTuple(args, "On", &py_lut, &i0)) {
 | 
				
			||||||
        PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
 | 
					        PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
 | 
				
			||||||
| 
						 | 
					@ -213,10 +216,12 @@ get_on_pixels(PyObject *self, PyObject *args) {
 | 
				
			||||||
    int row_idx, col_idx;
 | 
					    int row_idx, col_idx;
 | 
				
			||||||
    int width, height;
 | 
					    int width, height;
 | 
				
			||||||
    PyObject *ret = PyList_New(0);
 | 
					    PyObject *ret = PyList_New(0);
 | 
				
			||||||
 | 
					    if (ret == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!PyArg_ParseTuple(args, "n", &i0)) {
 | 
					    if (!PyArg_ParseTuple(args, "n", &i0)) {
 | 
				
			||||||
        PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
 | 
					        PyErr_SetString(PyExc_RuntimeError, "Argument parsing problem");
 | 
				
			||||||
 | 
					 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    img = (Imaging)i0;
 | 
					    img = (Imaging)i0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -439,6 +439,9 @@ path_tolist(PyPathObject *self, PyObject *args) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (flat) {
 | 
					    if (flat) {
 | 
				
			||||||
        list = PyList_New(self->count * 2);
 | 
					        list = PyList_New(self->count * 2);
 | 
				
			||||||
 | 
					        if (list == NULL) {
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        for (i = 0; i < self->count * 2; i++) {
 | 
					        for (i = 0; i < self->count * 2; i++) {
 | 
				
			||||||
            PyObject *item;
 | 
					            PyObject *item;
 | 
				
			||||||
            item = PyFloat_FromDouble(self->xy[i]);
 | 
					            item = PyFloat_FromDouble(self->xy[i]);
 | 
				
			||||||
| 
						 | 
					@ -449,6 +452,9 @@ path_tolist(PyPathObject *self, PyObject *args) {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        list = PyList_New(self->count);
 | 
					        list = PyList_New(self->count);
 | 
				
			||||||
 | 
					        if (list == NULL) {
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        for (i = 0; i < self->count; i++) {
 | 
					        for (i = 0; i < self->count; i++) {
 | 
				
			||||||
            PyObject *item;
 | 
					            PyObject *item;
 | 
				
			||||||
            item = Py_BuildValue("dd", self->xy[i + i], self->xy[i + i + 1]);
 | 
					            item = Py_BuildValue("dd", self->xy[i + i], self->xy[i + i + 1]);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user