Skip to content

Commit 19ca114

Browse files
gh-96819: multiprocessing.resource_tracker: check if length of pipe write <= 512 (#96890)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
1 parent 14d4f68 commit 19ca114

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/multiprocessing/resource_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ def unregister(self, name, rtype):
161161
def _send(self, cmd, name, rtype):
162162
self.ensure_running()
163163
msg = '{0}:{1}:{2}\n'.format(cmd, name, rtype).encode('ascii')
164-
if len(name) > 512:
164+
if len(msg) > 512:
165165
# posix guarantees that writes to a pipe of less than PIPE_BUF
166166
# bytes are atomic, and that PIPE_BUF >= 512
167-
raise ValueError('name too long')
167+
raise ValueError('msg too long')
168168
nbytes = os.write(self._fd, msg)
169169
assert nbytes == len(msg), "nbytes {0:n} but len(msg) {1:n}".format(
170170
nbytes, len(msg))

Lib/test/_test_multiprocessing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5432,6 +5432,14 @@ def test_resource_tracker_reused(self):
54325432

54335433
self.assertTrue(is_resource_tracker_reused)
54345434

5435+
def test_too_long_name_resource(self):
5436+
# gh-96819: Resource names that will make the length of a write to a pipe
5437+
# greater than PIPE_BUF are not allowed
5438+
rtype = "shared_memory"
5439+
too_long_name_resource = "a" * (512 - len(rtype))
5440+
with self.assertRaises(ValueError):
5441+
resource_tracker.register(too_long_name_resource, rtype)
5442+
54355443

54365444
class TestSimpleQueue(unittest.TestCase):
54375445

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed check in :mod:`multiprocessing.resource_tracker` that guarantees that the length of a write to a pipe is not greater than ``PIPE_BUF``.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy