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
2018-10-11 17:57:51 +00:00
2026-11-18 19:15:21 +03:00
2025-08-07 10:35:20 +03:00

OpenCV: Open Source Computer Vision Library

Resources

Contributing

Please read the contribution guidelines before starting work on a pull request.

Summary of the guidelines:

  • One pull request per issue;
  • Choose the right base branch: all new work goes to 5.x, while 4.x accepts only bug fixes and other minor fixes;
  • Include tests and documentation;
  • Clean up "oops" commits before submitting;
  • Follow the coding style guide.

Additional Resources

Description
Languages
C++ 87.7%
C 3.1%
Python 2.9%
CMake 2%
Java 1.5%
Other 2.6%