prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Conan crash if .count-files consist NULL-character
  conan version 1.8.0, Windows 7 x64
  
  For some reason (maybe a crash), the .count-files in each conan package in the cache were corrupted and contained a unicode NULL character (https://www.fileformat.info/info/unicode/char/0000/index.htm). This led to a conan crash for basically every package action (e.g. conan info).
  
  I already prepared a fix (https://github.com/conan-io/conan/compare/develop...pianoslum:develop) which also adds a little bit more verbosity in case there is no number in the .count-file.
  
  Is this enough info or should I elaborate?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `conans/util/locks.py`
  Content:
  ```
  1 import fasteners
  2 from conans.util.log import logger
  3 import time
  4 from conans.util.files import save, load
  5 import os
  6 
  7 
  8 class NoLock(object):
  9 
  10     def __enter__(self):
  11         pass
  12 
  13     def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable
  14         pass
  15 
  16 
  17 class SimpleLock(object):
  18 
  19     def __init__(self, filename):
  20         self._lock = fasteners.InterProcessLock(filename, logger=logger)
  21 
  22     def __enter__(self):
  23         self._lock.acquire()
  24 
  25     def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable
  26         self._lock.release()
  27 
  28 
  29 READ_BUSY_DELAY = 0.5
  30 WRITE_BUSY_DELAY = 0.25
  31 
  32 
  33 class Lock(object):
  34 
  35     @staticmethod
  36     def clean(folder):
  37         if os.path.exists(folder + ".count"):
  38             os.remove(folder + ".count")
  39         if os.path.exists(folder + ".count.lock"):
  40             os.remove(folder + ".count.lock")
  41 
  42     def __init__(self, folder, locked_item, output):
  43         self._count_file = folder + ".count"
  44         self._count_lock_file = folder + ".count.lock"
  45         self._locked_item = locked_item
  46         self._output = output
  47         self._first_lock = True
  48 
  49     @property
  50     def files(self):
  51         return (self._count_file, self._count_lock_file)
  52 
  53     def _info_locked(self):
  54         if self._first_lock:
  55             self._first_lock = False
  56             self._output.info("%s is locked by another concurrent conan process, wait..."
  57                               % str(self._locked_item))
  58             self._output.info("If not the case, quit, and do 'conan remove --locks'")
  59 
  60     def _readers(self):
  61         try:
  62             return int(load(self._count_file))
  63         except IOError:
  64             return 0
  65 
  66 
  67 class ReadLock(Lock):
  68 
  69     def __enter__(self):
  70         while True:
  71             with fasteners.InterProcessLock(self._count_lock_file, logger=logger):
  72                 readers = self._readers()
  73                 if readers >= 0:
  74                     save(self._count_file, str(readers + 1))
  75                     break
  76             self._info_locked()
  77             time.sleep(READ_BUSY_DELAY)
  78 
  79     def __exit__(self, exc_type, exc_val, exc_tb):   # @UnusedVariable
  80         with fasteners.InterProcessLock(self._count_lock_file, logger=logger):
  81             readers = self._readers()
  82             save(self._count_file, str(readers - 1))
  83 
  84 
  85 class WriteLock(Lock):
  86 
  87     def __enter__(self):
  88         while True:
  89             with fasteners.InterProcessLock(self._count_lock_file, logger=logger):
  90                 readers = self._readers()
  91                 if readers == 0:
  92                     save(self._count_file, "-1")
  93                     break
  94             self._info_locked()
  95             time.sleep(WRITE_BUSY_DELAY)
  96 
  97     def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable
  98         with fasteners.InterProcessLock(self._count_lock_file, logger=logger):
  99             save(self._count_file, "0")
  100
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/conans/util/locks.py b/conans/util/locks.py
  --- a/conans/util/locks.py
  +++ b/conans/util/locks.py
  @@ -60,7 +60,8 @@
       def _readers(self):
           try:
               return int(load(self._count_file))
  -        except IOError:
  +        except (IOError, UnicodeEncodeError, ValueError):
  +            self._output.warn("%s does not contain a number!" % self._count_file)
               return 0
  
verification_info: {"golden_diff": "diff --git a/conans/util/locks.py b/conans/util/locks.py\n--- a/conans/util/locks.py\n+++ b/conans/util/locks.py\n@@ -60,7 +60,8 @@\n     def _readers(self):\n         try:\n             return int(load(self._count_file))\n-        except IOError:\n+        except (IOError, UnicodeEncodeError, ValueError):\n+            self._output.warn(\"%s does not contain a number!\" % self._count_file)\n             return 0\n", "issue": "Conan crash if .count-files consist NULL-character\nconan version 1.8.0, Windows 7 x64\r\n\r\nFor some reason (maybe a crash), the .count-files in each conan package in the cache were corrupted and contained a unicode NULL character (https://www.fileformat.info/info/unicode/char/0000/index.htm). This led to a conan crash for basically every package action (e.g. conan info).\r\n\r\nI already prepared a fix (https://github.com/conan-io/conan/compare/develop...pianoslum:develop) which also adds a little bit more verbosity in case there is no number in the .count-file.\r\n\r\nIs this enough info or should I elaborate?\n", "before_files": [{"content": "import fasteners\nfrom conans.util.log import logger\nimport time\nfrom conans.util.files import save, load\nimport os\n\n\nclass NoLock(object):\n\n    def __enter__(self):\n        pass\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        pass\n\n\nclass SimpleLock(object):\n\n    def __init__(self, filename):\n        self._lock = fasteners.InterProcessLock(filename, logger=logger)\n\n    def __enter__(self):\n        self._lock.acquire()\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        self._lock.release()\n\n\nREAD_BUSY_DELAY = 0.5\nWRITE_BUSY_DELAY = 0.25\n\n\nclass Lock(object):\n\n    @staticmethod\n    def clean(folder):\n        if os.path.exists(folder + \".count\"):\n            os.remove(folder + \".count\")\n        if os.path.exists(folder + \".count.lock\"):\n            os.remove(folder + \".count.lock\")\n\n    def __init__(self, folder, locked_item, output):\n        self._count_file = folder + \".count\"\n        self._count_lock_file = folder + \".count.lock\"\n        self._locked_item = locked_item\n        self._output = output\n        self._first_lock = True\n\n    @property\n    def files(self):\n        return (self._count_file, self._count_lock_file)\n\n    def _info_locked(self):\n        if self._first_lock:\n            self._first_lock = False\n            self._output.info(\"%s is locked by another concurrent conan process, wait...\"\n                              % str(self._locked_item))\n            self._output.info(\"If not the case, quit, and do 'conan remove --locks'\")\n\n    def _readers(self):\n        try:\n            return int(load(self._count_file))\n        except IOError:\n            return 0\n\n\nclass ReadLock(Lock):\n\n    def __enter__(self):\n        while True:\n            with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n                readers = self._readers()\n                if readers >= 0:\n                    save(self._count_file, str(readers + 1))\n                    break\n            self._info_locked()\n            time.sleep(READ_BUSY_DELAY)\n\n    def __exit__(self, exc_type, exc_val, exc_tb):   # @UnusedVariable\n        with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n            readers = self._readers()\n            save(self._count_file, str(readers - 1))\n\n\nclass WriteLock(Lock):\n\n    def __enter__(self):\n        while True:\n            with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n                readers = self._readers()\n                if readers == 0:\n                    save(self._count_file, \"-1\")\n                    break\n            self._info_locked()\n            time.sleep(WRITE_BUSY_DELAY)\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n            save(self._count_file, \"0\")\n", "path": "conans/util/locks.py"}], "after_files": [{"content": "import fasteners\nfrom conans.util.log import logger\nimport time\nfrom conans.util.files import save, load\nimport os\n\n\nclass NoLock(object):\n\n    def __enter__(self):\n        pass\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        pass\n\n\nclass SimpleLock(object):\n\n    def __init__(self, filename):\n        self._lock = fasteners.InterProcessLock(filename, logger=logger)\n\n    def __enter__(self):\n        self._lock.acquire()\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        self._lock.release()\n\n\nREAD_BUSY_DELAY = 0.5\nWRITE_BUSY_DELAY = 0.25\n\n\nclass Lock(object):\n\n    @staticmethod\n    def clean(folder):\n        if os.path.exists(folder + \".count\"):\n            os.remove(folder + \".count\")\n        if os.path.exists(folder + \".count.lock\"):\n            os.remove(folder + \".count.lock\")\n\n    def __init__(self, folder, locked_item, output):\n        self._count_file = folder + \".count\"\n        self._count_lock_file = folder + \".count.lock\"\n        self._locked_item = locked_item\n        self._output = output\n        self._first_lock = True\n\n    @property\n    def files(self):\n        return (self._count_file, self._count_lock_file)\n\n    def _info_locked(self):\n        if self._first_lock:\n            self._first_lock = False\n            self._output.info(\"%s is locked by another concurrent conan process, wait...\"\n                              % str(self._locked_item))\n            self._output.info(\"If not the case, quit, and do 'conan remove --locks'\")\n\n    def _readers(self):\n        try:\n            return int(load(self._count_file))\n        except (IOError, UnicodeEncodeError, ValueError):\n            self._output.warn(\"%s does not contain a number!\" % self._count_file)\n            return 0\n\n\nclass ReadLock(Lock):\n\n    def __enter__(self):\n        while True:\n            with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n                readers = self._readers()\n                if readers >= 0:\n                    save(self._count_file, str(readers + 1))\n                    break\n            self._info_locked()\n            time.sleep(READ_BUSY_DELAY)\n\n    def __exit__(self, exc_type, exc_val, exc_tb):   # @UnusedVariable\n        with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n            readers = self._readers()\n            save(self._count_file, str(readers - 1))\n\n\nclass WriteLock(Lock):\n\n    def __enter__(self):\n        while True:\n            with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n                readers = self._readers()\n                if readers == 0:\n                    save(self._count_file, \"-1\")\n                    break\n            self._info_locked()\n            time.sleep(WRITE_BUSY_DELAY)\n\n    def __exit__(self, exc_type, exc_val, exc_tb):  # @UnusedVariable\n        with fasteners.InterProcessLock(self._count_lock_file, logger=logger):\n            save(self._count_file, \"0\")\n", "path": "conans/util/locks.py"}]}