From b4496cc42c5953da3a7f5d54e88616c86ffa5c07 Mon Sep 17 00:00:00 2001 From: lovasoa Date: Thu, 1 Jul 2021 19:45:16 +0200 Subject: [PATCH 1/2] Avoid putting the process in a zombie state when encountering non-unicode filenames This patch matches the behavior of the python3 branch on python2: If a file's name is not a valid string in the filesystem's character encoding, then it is processed with a filename string where the invalid characters are encoded as unicode surrogate pairs. This matches the behavior of os.fsdecode which is used on python 3 https://docs.python.org/3/library/os.html#os.fsdecode --- src/watchdog/utils/unicode_paths.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/watchdog/utils/unicode_paths.py b/src/watchdog/utils/unicode_paths.py index 501a2f151..4bcef7814 100644 --- a/src/watchdog/utils/unicode_paths.py +++ b/src/watchdog/utils/unicode_paths.py @@ -55,10 +55,13 @@ def encode(path): def decode(path): if isinstance(path, bytes_cls): + # Try the filesystem encoding and the fallback encoding. + # If all fails, encode invalid characters using surrogate pairs try: path = path.decode(fs_encoding, 'strict') except UnicodeDecodeError: - if not platform.is_linux(): - raise - path = path.decode(fs_fallback_encoding, 'strict') + try: + path = path.decode(fs_fallback_encoding, 'strict') + except UnicodeDecodeError: + path = path.decode(fs_encoding, 'surrogateescape') return path From d863020c8816d1ec0a6e44d92846ad84a5a8c5ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Schoentgen?= Date: Thu, 1 Jul 2021 19:56:12 +0200 Subject: [PATCH 2/2] Update changelog.rst --- changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.rst b/changelog.rst index f2cb99689..250637c3d 100644 --- a/changelog.rst +++ b/changelog.rst @@ -8,6 +8,7 @@ Changelog 202x-xx-xx • `full history `__ +- Avoid crashing the event processing thread on non-utf8 filenames (`#811 `_) - [backport 1.0.0] [mac] Regression fixes for native ``fsevents`` (`#717 `_) - [backport 1.0.0] [windows] ``winapi.BUFFER_SIZE`` now defaults to ``64000`` (instead of ``2048``) (`#700 `_) - [backport 1.0.0] [windows] Introduced ``winapi.PATH_BUFFER_SIZE`` (defaults to ``2048``) to keep the old behavior with path-realted functions (`#700 `_) @@ -21,7 +22,7 @@ Changelog - [backport 2.0.0] [mac] Support coalesced filesystem events (`#734 `_) - [backport 2.0.0] [mac] Drop support for OSX 10.12 and earlier (`#750 `_) - [backport 2.0.0] [mac] Fix an issue when renaming an item changes only the casing (`#750 `_) -- Thanks to our beloved contributors: @SamSchott, @bstaletic, @BoboTiG, @CCP-Aporia, @di, @lukassup, @ysard +- Thanks to our beloved contributors: @SamSchott, @bstaletic, @BoboTiG, @CCP-Aporia, @di, @lukassup, @ysard, @lovasoa 0.10.6