Files
opencv-MIRROR/modules
Abhishek Gola 7ab720c3d1 Merge pull request #31324 from kari-pikkarainen/fix/python-lone-surrogate-5.x
5.x port of #31296 (merged to 4.x), requested there. It is a clean cherry-pick of the same change.

A Python str containing a lone surrogate, such as 'a\udcff', crashes the interpreter when it is passed to bindings that take a string, for example cv.putText, cv.imread or cv.imwrite. Python produces such strings for non-UTF-8 filenames on POSIX.

getUnicodeString() in modules/python/src2/pycompat.hpp passed the NULL that PyUnicode_AsUTF8String() returns on failure to PyBytes_Check(). This PR adds the NULL check, so the pending UnicodeEncodeError is reported instead.

Difference from 4.x: cv.getTextSize raises cv.error here, because 5.x has another overload; 4.x raises UnicodeEncodeError.
2026-12-02 22:40:18 +05:30
..
2026-12-01 23:18:38 +05:30