diff --git a/py3.10/README_MODS b/py3.10/README_MODS index 66dbe86..f62e36c 100644 --- a/py3.10/README_MODS +++ b/py3.10/README_MODS @@ -857,4 +857,23 @@ $ diff Python-3.10.5/Lib/test/_test_multiprocessing.py Python-3.10.6/Lib/test/_t > name = f'test_semlock_subclass-{os.getpid()}' > s = SemLock(1, 0, 10, name, 0) > _multiprocessing.sem_unlink(name) - +# ---------------------------------------------------------------------- +diff Python-3.10.6/Lib/multiprocessing/resource_tracker.py Python-3.10.8/Lib/multiprocessing/resource_tracker.py +164c164 +< if len(name) > 512: +--- +> if len(msg) > 512: +167c167 +< raise ValueError('name too long') +--- +> raise ValueError('msg too long') +diff Python-3.10.6/Lib/test/_test_multiprocessing.py Python-3.10.8/Lib/test/_test_multiprocessing.py +5379a5380,5387 +> def test_too_long_name_resource(self): +> # gh-96819: Resource names that will make the length of a write to a pipe +> # greater than PIPE_BUF are not allowed +> rtype = "shared_memory" +> too_long_name_resource = "a" * (512 - len(rtype)) +> with self.assertRaises(ValueError): +> resource_tracker.register(too_long_name_resource, rtype) +> diff --git a/py3.10/multiprocess/resource_tracker.py b/py3.10/multiprocess/resource_tracker.py index 4ec3eaa..983e57e 100644 --- a/py3.10/multiprocess/resource_tracker.py +++ b/py3.10/multiprocess/resource_tracker.py @@ -164,10 +164,10 @@ def unregister(self, name, rtype): def _send(self, cmd, name, rtype): self.ensure_running() msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii') - if len(name) > 512: + if len(msg) > 512: # posix guarantees that writes to a pipe of less than PIPE_BUF # bytes are atomic, and that PIPE_BUF >= 512 - raise ValueError('name too long') + raise ValueError('msg too long') nbytes = os.write(self._fd, msg) assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format( nbytes, len(msg)) diff --git a/py3.10/multiprocess/tests/__init__.py b/py3.10/multiprocess/tests/__init__.py index f9aa038..cbbfea2 100644 --- a/py3.10/multiprocess/tests/__init__.py +++ b/py3.10/multiprocess/tests/__init__.py @@ -5386,6 +5386,14 @@ def test_resource_tracker_reused(self): self.assertTrue(is_resource_tracker_reused) + def test_too_long_name_resource(self): + # gh-96819: Resource names that will make the length of a write to a pipe + # greater than PIPE_BUF are not allowed + rtype = "shared_memory" + too_long_name_resource = "a" * (512 - len(rtype)) + with self.assertRaises(ValueError): + resource_tracker.register(too_long_name_resource, rtype) + class TestSimpleQueue(unittest.TestCase):