From 2efc372895bca0c6e6c8cc9ad6802efe2ffed77c Mon Sep 17 00:00:00 2001 From: saito828koki Date: Sat, 17 Sep 2022 21:50:14 +0900 Subject: [PATCH 1/8] fix: check the length of `msg`, not the length of `name` --- Lib/multiprocessing/resource_tracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/multiprocessing/resource_tracker.py b/Lib/multiprocessing/resource_tracker.py index cc42dbdda05b91..ca27eb7c0e8ec2 100644 --- a/Lib/multiprocessing/resource_tracker.py +++ b/Lib/multiprocessing/resource_tracker.py @@ -161,7 +161,7 @@ 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') From 476bed09dde6e28c28e356d0c13f1cdeed7848fa Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 17 Sep 2022 13:15:11 +0000 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst diff --git a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst new file mode 100644 index 00000000000000..0511d56b81c175 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst @@ -0,0 +1 @@ +Fixed the block to guarantee that the length of a write to a pipe is not greater than `PIPE_BUF` From ee548f9643bb897583e602d2f5f7b7c9207287ef Mon Sep 17 00:00:00 2001 From: Koki Saito <49419225+saito828koki@users.noreply.github.com> Date: Sat, 17 Sep 2022 22:30:51 +0900 Subject: [PATCH 3/8] fix: remove backticks --- .../next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst index 0511d56b81c175..d204b20bd272ad 100644 --- a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst +++ b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst @@ -1 +1 @@ -Fixed the block to guarantee that the length of a write to a pipe is not greater than `PIPE_BUF` +Fixed the block to guarantee that the length of a write to a pipe is not greater than PIPE_BUF From 1566b72c11ed89916c9fef1214fb35c98a4a40b6 Mon Sep 17 00:00:00 2001 From: saito828koki Date: Tue, 20 Sep 2022 16:33:27 +0900 Subject: [PATCH 4/8] fix: update error message --- Lib/multiprocessing/resource_tracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/multiprocessing/resource_tracker.py b/Lib/multiprocessing/resource_tracker.py index ca27eb7c0e8ec2..ea369507297f86 100644 --- a/Lib/multiprocessing/resource_tracker.py +++ b/Lib/multiprocessing/resource_tracker.py @@ -164,7 +164,7 @@ def _send(self, cmd, name, rtype): 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)) From 3f32cb68b2a8f7008c6fb0afc6ffc0f6ad222bc4 Mon Sep 17 00:00:00 2001 From: saito828koki Date: Tue, 20 Sep 2022 16:46:42 +0900 Subject: [PATCH 5/8] modify NEWS entry --- .../next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst index d204b20bd272ad..eac61c9e379c41 100644 --- a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst +++ b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst @@ -1 +1 @@ -Fixed the block to guarantee that the length of a write to a pipe is not greater than PIPE_BUF +Fixed the check that guarantees that the length of a write to a pipe is not greater than PIPE_BUF From 103964826fb33d75483ca4cd2e35c27bc65a6d16 Mon Sep 17 00:00:00 2001 From: saito828koki Date: Sat, 1 Oct 2022 20:56:15 +0900 Subject: [PATCH 6/8] Add a test for too long name resources --- Lib/test/_test_multiprocessing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index b78586c560a68a..6ba7ee4ef18df0 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -5433,6 +5433,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): From 30f651c3f561503c50345c41a5062fff4b04cd90 Mon Sep 17 00:00:00 2001 From: saito828koki Date: Sun, 2 Oct 2022 02:41:38 +0900 Subject: [PATCH 7/8] Modify NEWS entry --- .../next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst index eac61c9e379c41..6e4672aa3882ec 100644 --- a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst +++ b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst @@ -1 +1 @@ -Fixed the check that guarantees that the length of a write to a pipe is not greater than PIPE_BUF +Fixed the check in :mod:`multiprocessing.resource_tracker` that guarantees that the length of a write to a pipe is not greater than PIPE_BUF From 6c3afb9eab4e93a30c4105d790393dac73374b8a Mon Sep 17 00:00:00 2001 From: Koki Saito <49419225+saito828koki@users.noreply.github.com> Date: Sun, 2 Oct 2022 02:55:31 +0900 Subject: [PATCH 8/8] Modify NEWS entry Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- .../next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst index 6e4672aa3882ec..07b62a883b85e7 100644 --- a/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst +++ b/Misc/NEWS.d/next/Library/2022-09-17-13-15-10.gh-issue-96819.6RfqM7.rst @@ -1 +1 @@ -Fixed the check in :mod:`multiprocessing.resource_tracker` that guarantees that the length of a write to a pipe is not greater than PIPE_BUF +Fixed check in :mod:`multiprocessing.resource_tracker` that guarantees that the length of a write to a pipe is not greater than ``PIPE_BUF``.