Skip to content

gh-121313: Limit the reading size from pipes to their default buffer size on Unix systems #121314

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

Closed
wants to merge 12 commits into from
14 changes: 14 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11341,6 +11341,20 @@
}

length = Py_MIN(length, _PY_READ_MAX);

static long page_size;
if (page_size == 0)
page_size = sysconf(_SC_PAGE_SIZE);

Check warning on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'sysconf' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'_SC_PAGE_SIZE': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

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

'sysconf' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

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

'_SC_PAGE_SIZE': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'sysconf' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build (arm64)

'_SC_PAGE_SIZE': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

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

'sysconf' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 11347 in Modules/posixmodule.c

View workflow job for this annotation

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

'_SC_PAGE_SIZE': undeclared identifier [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

#ifndef MS_WINDOWS
if (length > page_size * 16) {
struct stat statbuffer;
fstat(fd, &statbuffer);
if (S_ISFIFO(statbuffer.st_mode)) {
length = Py_MIN(page_size* 16, length);
}
}
#endif

buffer = PyBytes_FromStringAndSize((char *)NULL, length);
if (buffer == NULL)
Expand Down
Loading