Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-134453: Fix subprocess memoryview input handling on POSIX#134949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
gpshead wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
fromgpshead:subprocess-posix-input-memoryview

Conversation

gpshead
Copy link
Member

@gpsheadgpshead commentedMay 30, 2025
edited by bedevere-appbot
Loading

Fix inconsistent subprocess.Popen.communicate() behavior between Windows and POSIX when using memoryview objects with non-byte elements as input.

On POSIX systems, the code was incorrectly comparing bytes written against element count instead of byte count, causing data truncation for large inputs with non-byte element types.

Changes:

  • Cast memoryview inputs to byte view when input is already a memoryview
  • Fix progress tracking to use len(input_view) instead of len(self._input)
  • Added tests for memoryview inputs

Fix inconsistent subprocess.Popen.communicate() behavior between Windowsand POSIX when using memoryview objects with non-byte elements as input.On POSIX systems, the code was incorrectly comparing bytes written againstelement count instead of byte count, causing data truncation for largeinputs with non-byte element types.Changes:- Cast memoryview inputs to byte view when input is already a memoryview- Fix progress tracking to use len(input_view) instead of len(self._input)- Add comprehensive test coverage for memoryview inputs🤖 Generated with [Claude Code](https://claude.ai/code)Co-Authored-By: Claude <noreply@anthropic.com>pre-commit-whitespace-fixup
@gpsheadgpsheadforce-pushed thesubprocess-posix-input-memoryview branch frome1e8e52 to6cd5c60CompareMay 30, 2025 18:42
@gpsheadgpsheadforce-pushed thesubprocess-posix-input-memoryview branch from6cd5c60 to7e1e75cCompareMay 30, 2025 18:55
self.addCleanup(p.stdin.close)
(stdout, stderr) = p.communicate(mv)
self.assertEqual(stdout, test_data)
self.assertEqual(stderr, None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

UseassertIsNone

Suggested change
self.assertEqual(stderr,None)
self.assertIsNone(stderr,None)

self.addCleanup(p.stdin.close)
(stdout, stderr) = p.communicate(mv)
self.assertEqual(stdout, expected_bytes)
self.assertEqual(stderr, None)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
self.assertEqual(stderr,None)
self.assertIsNone(stderr,None)

Comment on lines +984 to +985
num_elements = (pipe_buf // 4) + 100
test_array = array.array('i', range(num_elements)) # 'i' = signed int (4 bytes each)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hmm, this test passes on the main branch. I think we want something like this:

Suggested change
num_elements=(pipe_buf//4)+100
test_array=array.array('i',range(num_elements))# 'i' = signed int (4 bytes each)
num_elements=pipe_buf+1
test_array=array.array('i',[1for_inrange(num_elements)])

From what I can tell, the pipe is taking each integer as a single byte.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ZeroIntensityZeroIntensityZeroIntensity left review comments

Assignees

@gpsheadgpshead

Labels
awaiting core reviewneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixes
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@gpshead@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp