Simplify FreeTypeFont.getmask2()#7645
Conversation
There was a problem hiding this comment.
I had imagined that raising a DecompressionBombError during a Python callback from C was somehow bad, but our test suite triggers that scenario with your branch, and it is fine.
Presuming that the memory management in fine (I've checked oss-fuzz with the test case from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60273 and it passed), I approve - but it is probably not the best idea to adjust code that fixed an oss-fuzz problem less than a week before release, so I suggest holding off on this for now
Sure, that sounds reasonable. |
Changes proposed in this pull request:
Image._decompression_bomb_checkdirectly infillrather than duplicating its code. If an error is raised, it is propagated via theif (image == NULL)branch.imageobject by releasing the only reference to it (causing Python to call itstp_deallocslot, i.e._deallocin_imaging.c) instead of just freeing the memory it points to (added in Improved checks in font_render #7218).typing.castorassert size is not None).This partially reverts changes from #7246, which was connected to an oss-fuzz error, but I do not see any added tests or reproduction steps. IIUC, the original error was a memory leak, which I avoid in a different way in this PR:
The original code (before #7246) returned
imageviaOformat (returning a new reference) and did notPy_DECREF(causing a memory leak).#7246 instead returns a reference via a nonlocal Python variable and added
Py_DECREF.In this PR I have removed the nonlocal variable and return the existing reference via
Nformat.See https://docs.python.org/3/c-api/arg.html#c.Py_BuildValue for the difference between
OandN.