mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
Guard against overflows when using the lo32 api
If psycopg supports lo64 but the server doesn't the user may pass values that would overflow the api range, resulting in: lo.seek((2<<30)) *** OperationalError: ERROR: invalid seek offset: -2147483648 Also improved the error messages and guard against INT_MIN for negative seek offsets.
This commit is contained in:
parent
79df47a146
commit
2f862972c9
|
@ -175,10 +175,21 @@ psyco_lobj_seek(lobjectObject *self, PyObject *args)
|
|||
EXC_IF_LOBJ_LEVEL0(self);
|
||||
EXC_IF_LOBJ_UNMARKED(self);
|
||||
|
||||
#ifndef HAVE_LO64
|
||||
if (offset > INT_MAX) {
|
||||
psyco_set_error(InterfaceError, NULL,
|
||||
"offset out of range");
|
||||
#ifdef HAVE_LO64
|
||||
if ((offset < INT_MIN || offset > INT_MAX)
|
||||
&& self->conn->server_version < 90300) {
|
||||
PyErr_Format(NotSupportedError,
|
||||
"offset out of range (%ld): server version %d "
|
||||
"does not support the lobject 64 API",
|
||||
offset, self->conn->server_version);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if (offset < INT_MIN || offset > INT_MAX) {
|
||||
PyErr_Format(InterfaceError,
|
||||
"offset out of range (%ld): this psycopg version was not built "
|
||||
"with lobject 64 API support",
|
||||
offset);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
@ -272,10 +283,20 @@ psyco_lobj_truncate(lobjectObject *self, PyObject *args)
|
|||
EXC_IF_LOBJ_LEVEL0(self);
|
||||
EXC_IF_LOBJ_UNMARKED(self);
|
||||
|
||||
#ifndef HAVE_LO64
|
||||
#ifdef HAVE_LO64
|
||||
if (len > INT_MAX && self->conn->server_version < 90300) {
|
||||
PyErr_Format(NotSupportedError,
|
||||
"len out of range (%ld): server version %d "
|
||||
"does not support the lobject 64 API",
|
||||
len, self->conn->server_version);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
if (len > INT_MAX) {
|
||||
psyco_set_error(InterfaceError, NULL,
|
||||
"len out of range");
|
||||
PyErr_Format(InterfaceError,
|
||||
"len out of range (%ld): this psycopg version was not built "
|
||||
"with lobject 64 API support",
|
||||
len);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user