Check if PyObject_CallMethod result is NULL (#9494)
This commit is contained in:
parent
43e4ebe037
commit
da729c832c
@ -175,8 +175,15 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
|
||||
|
||||
/* Get all data from File descriptor */
|
||||
c = (SGISTATE *)state->context;
|
||||
_imaging_seek_pyFd(state->fd, 0L, SEEK_END);
|
||||
if (_imaging_seek_pyFd(state->fd, 0L, SEEK_END) == -1) {
|
||||
state->errcode = IMAGING_CODEC_UNKNOWN;
|
||||
return -1;
|
||||
}
|
||||
c->bufsize = _imaging_tell_pyFd(state->fd);
|
||||
if (c->bufsize == -1) {
|
||||
state->errcode = IMAGING_CODEC_UNKNOWN;
|
||||
return -1;
|
||||
}
|
||||
c->bufsize -= SGI_HEADER_SIZE;
|
||||
|
||||
c->tablen = im->bands * im->ysize;
|
||||
@ -194,8 +201,8 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
|
||||
state->errcode = IMAGING_CODEC_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
_imaging_seek_pyFd(state->fd, SGI_HEADER_SIZE, SEEK_SET);
|
||||
if (_imaging_read_pyFd(state->fd, (char *)ptr, c->bufsize) != c->bufsize) {
|
||||
if (_imaging_seek_pyFd(state->fd, SGI_HEADER_SIZE, SEEK_SET) == -1 ||
|
||||
_imaging_read_pyFd(state->fd, (char *)ptr, c->bufsize) != c->bufsize) {
|
||||
free(ptr);
|
||||
state->errcode = IMAGING_CODEC_UNKNOWN;
|
||||
return -1;
|
||||
|
||||
@ -12,6 +12,9 @@ _imaging_read_pyFd(PyObject *fd, char *dest, Py_ssize_t bytes) {
|
||||
int bytes_result;
|
||||
|
||||
result = PyObject_CallMethod(fd, "read", "n", bytes);
|
||||
if (result == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
bytes_result = PyBytes_AsStringAndSize(result, &buffer, &length);
|
||||
if (bytes_result == -1) {
|
||||
@ -28,7 +31,7 @@ _imaging_read_pyFd(PyObject *fd, char *dest, Py_ssize_t bytes) {
|
||||
return length;
|
||||
|
||||
err:
|
||||
Py_DECREF(result);
|
||||
Py_XDECREF(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -41,6 +44,10 @@ _imaging_write_pyFd(PyObject *fd, char *src, Py_ssize_t bytes) {
|
||||
result = PyObject_CallMethod(fd, "write", "O", byteObj);
|
||||
|
||||
Py_DECREF(byteObj);
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_DECREF(result);
|
||||
|
||||
return bytes;
|
||||
@ -51,6 +58,9 @@ _imaging_seek_pyFd(PyObject *fd, Py_ssize_t offset, int whence) {
|
||||
PyObject *result;
|
||||
|
||||
result = PyObject_CallMethod(fd, "seek", "ni", offset, whence);
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_DECREF(result);
|
||||
return 0;
|
||||
@ -62,6 +72,9 @@ _imaging_tell_pyFd(PyObject *fd) {
|
||||
Py_ssize_t location;
|
||||
|
||||
result = PyObject_CallMethod(fd, "tell", NULL);
|
||||
if (result == NULL) {
|
||||
return -1;
|
||||
}
|
||||
location = PyLong_AsSsize_t(result);
|
||||
|
||||
Py_DECREF(result);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user