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-135862: fix asyncio socket partial writes of non-1d-binary arrays#135974

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
duaneg wants to merge3 commits intopython:main
base:main
Choose a base branch
Loading
fromduaneg:gh-135862

Conversation

duaneg
Copy link
Contributor

@duanegduaneg commentedJun 26, 2025
edited
Loading

Theasyncio code is writing binary data to asocket.socket, and advancing through the buffer after a partial write by doingmemoryview(data)[n:], wheren is the number of bytes written.

This assumes thememoryview is a one dimensional buffer of bytes, which is not the case e.g. for amemoryview of anarray.array of non-bytes, or anndarray with more than one dimension. Partial writes of suchmemoryviews will corrupt the stream, repeating or omitting some data.

When creating amemoryview from amemoryview, first convert it to a one-dimensional array of bytes before taking the remaining slice, thus avoiding these issues.

Add an assertion that the remaining data is bytes, to guard against possible regressions if additional types of data are allowed in the future.

…rraysThe :mod:`asyncio` code is writing binary data to a :class:`socket.socket`, andadvancing through the buffer after a partial write by doing``memoryview(data)[n:]``, where ``n`` is the number of bytes written.This assumes the :class:`memoryview` is a one dimensional buffer of bytes,which is not the case e.g. for a :class:`memoryview` of an :class:`array.array`of non-bytes, or an ``ndarray`` with more than one dimension. Partial writes ofsuch :class:`memoryview`s will corrupt the stream, repeating or omitting somedata.When creating a :class:`memoryview` from a :class:`memoryview`, first convertit to a one-dimensional array of bytes before taking the remaining slice, thusavoiding these issues.Add an assertion that the remaining data is bytes, to guard against possibleregressions if additional types of data are allowed in the future.
Hopefully this will fix the windows compile failures...
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@duaneg

[8]ページ先頭

©2009-2025 Movatter.jp