8000 gh-129205: Add os.readinto API for reading data into a caller provided buffer by cmaloney · Pull Request #129211 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-129205: Add os.readinto API for reading data into a caller provided buffer #129211

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 26, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove length cap, and early exit on negative len.
Py_ssize_t can't get as big as Py_size_t, _Py_read checks max length
  • Loading branch information
cmaloney committed Jan 23, 2025
commit 992d5f51e5d8c7f8e4af1d011ae7fb9127d84708
8 changes: 5 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11451,9 +11451,11 @@
os_readinto_impl(PyObject *module, int fd, Py_buffer *buffer)
/*[clinic end generated code: output=8091a3513c683a80 input=810c820f4d9b1c6b]*/
{
// Cap to max read size to prevent overflow in cast to size_t for _Py_read.
size_t length = Py_MIN(buffer->len, _PY_READ_MAX);
return _Py_read(fd, buffer->buf, length);
if (buffer->len < 0) {
errno = EINVAL
return posix_error();

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

expected ‘;’ before ‘return’

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

expected ‘;’ before ‘return’

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

syntax error: missing ';' before 'return' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'return': 'Py_ssize_t' differs in levels of indirection from 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

syntax error: missing ';' before 'return' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'return': 'Py_ssize_t' differs in levels of indirection from 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

syntax error: missing ';' before 'return' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'return': 'Py_ssize_t' differs in levels of indirection from 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

syntax error: missing ';' before 'return' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'return': 'Py_ssize_t' differs in levels of indirection from 'PyObject *' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11456 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

expected ‘;’ before ‘return’
}
return _Py_read(fd, buffer->buf, buffer->len);
}

#if (defined(HAVE_SENDFILE) && (defined(__FreeBSD__) || defined(__DragonFly__) \
Expand Down
Loading
0