|
1 | 1 | #include <cmath> |
| 2 | +#include <limits> |
2 | 3 |
|
3 | 4 | #include <effectengine/Effect.h> |
4 | 5 | #include <effectengine/EffectModule.h> |
@@ -277,12 +278,26 @@ PyObject* EffectModule::wrapSetImage(PyObject* /*self*/, PyObject* args) |
277 | 278 | { |
278 | 279 | if (PyByteArray_Check(bytearray)) |
279 | 280 | { |
| 281 | + if (width <= 0 || height <= 0) |
| 282 | + { |
| 283 | + PyErr_SetString(PyExc_ValueError, "Image width and height must be positive"); |
| 284 | + return nullptr; |
| 285 | + } |
| 286 | + |
280 | 287 | Py_ssize_t length = PyByteArray_Size(bytearray); |
281 | | - if (length == 3 * width * height) |
| 288 | + const uint64_t pixelCount = static_cast<uint64_t>(width) * static_cast<uint64_t>(height); |
| 289 | + if (pixelCount > static_cast<uint64_t>(std::numeric_limits<Py_ssize_t>::max()) / 3U) |
| 290 | + { |
| 291 | + PyErr_SetString(PyExc_OverflowError, "Image dimensions are too large"); |
| 292 | + return nullptr; |
| 293 | + } |
| 294 | + |
| 295 | + const Py_ssize_t expectedLength = static_cast<Py_ssize_t>(pixelCount * 3U); |
| 296 | + if (length == expectedLength) |
282 | 297 | { |
283 | 298 | Image<ColorRgb> image(width, height); |
284 | 299 | const char* data = PyByteArray_AS_STRING(bytearray); |
285 | | - memcpy(image.memptr(), data, length); |
| 300 | + memcpy(image.memptr(), data, static_cast<size_t>(length)); |
286 | 301 | emit getEffect()->setInputImage(getEffect()->_priority, image, getEffect()->getRemaining(), false); |
287 | 302 | Py_RETURN_NONE; |
288 | 303 | } |
@@ -906,7 +921,12 @@ PyObject* EffectModule::wrapImageDrawPie(PyObject* /*self*/, PyObject* args) |
906 | 921 | (uint8_t)(data[idx + 4]) |
907 | 922 | )); |
908 | 923 | } |
| 924 | + |
909 | 925 | painter->setBrush(gradient); |
| 926 | + QPen oldPen = painter->pen(); |
| 927 | + painter->setPen(Qt::NoPen); |
| 928 | + painter->drawPie(centerX - radius, centerY - radius, radius * 2, radius * 2, startAngle * 16, spanAngle * 16); |
| 929 | + painter->setPen(oldPen); |
910 | 930 | Py_RETURN_NONE; |
911 | 931 | } |
912 | 932 |
|
@@ -1185,11 +1205,10 @@ PyObject* EffectModule::wrapImageCOffset(PyObject* /*self*/, PyObject* args) |
1185 | 1205 | { |
1186 | 1206 | int offsetX = 0; |
1187 | 1207 | int offsetY = 0; |
1188 | | - Py_ssize_t argCount = PyTuple_Size(args); |
1189 | | - |
1190 | | - if (argCount == 2) |
| 1208 | + if (!PyArg_ParseTuple(args, "ii", &offsetX, &offsetY)) |
1191 | 1209 | { |
1192 | | - PyArg_ParseTuple(args, "ii", &offsetX, &offsetY); |
| 1210 | + if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "Invalid argument count or type."); } |
| 1211 | + return nullptr; |
1193 | 1212 | } |
1194 | 1213 |
|
1195 | 1214 | getEffect()->_painter->translate(QPoint(offsetX, offsetY)); |
|
0 commit comments