Cast Dib handle to int by radarhere · Pull Request #8385 · python-pillow/Pillow

Resolves #8383

The Dib class passes handle to core method getdc() in expose()

if isinstance(handle, HWND):
dc = self.image.getdc(handle)

but despite what our Python logic would lead you to expect, it must be an integer. See the following code and https://docs.python.org/3/c-api/arg.html#numbers

#if SIZEOF_VOID_P == 8
#define F_HANDLE "K"
#else
#define F_HANDLE "k"
#endif

_getdc(ImagingDisplayObject *display, PyObject *args) {
HWND window;
HDC dc;
if (!PyArg_ParseTuple(args, F_HANDLE, &window)) {

So this PR casts it to an integer in Python first. The same logic also applies to draw() and query_palette().