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

Skip to content

Commit 3f658be

Browse files
committed
sqlite: raise an OverflowError if a string or a BLOB is longer than INT_MAX
bytes Fix compiler warnings on Windows 64-bit
1 parent 83e30bf commit 3f658be

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

Modules/_sqlite/statement.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,26 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
132132
break;
133133
case TYPE_UNICODE:
134134
string = _PyUnicode_AsStringAndSize(parameter, &buflen);
135-
if (string != NULL)
136-
rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
137-
else
138-
rc = -1;
135+
if (string == NULL)
136+
return -1;
137+
if (buflen > INT_MAX) {
138+
PyErr_SetString(PyExc_OverflowError,
139+
"string longer than INT_MAX bytes");
140+
return -1;
141+
}
142+
rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
139143
break;
140144
case TYPE_BUFFER:
141-
if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
142-
rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
143-
} else {
145+
if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) != 0) {
144146
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
145-
rc = -1;
147+
return -1;
148+
}
149+
if (buflen > INT_MAX) {
150+
PyErr_SetString(PyExc_OverflowError,
151+
"BLOB longer than INT_MAX bytes");
152+
return -1;
146153
}
154+
rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
147155
break;
148156
case TYPE_UNKNOWN:
149157
rc = -1;

0 commit comments

Comments
 (0)