Skip to content

Commit 5f23181

Browse files
committed
cap the block size to 8 MB.
1 parent dc44c98 commit 5f23181

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Lib/_pyio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
241241
buffering = -1
242242
line_buffering = True
243243
if buffering < 0:
244-
buffering = max(raw._blksize, DEFAULT_BUFFER_SIZE)
244+
buffering = max(min(raw._blksize, 8192 * 1024), DEFAULT_BUFFER_SIZE)
245245
if buffering < 0:
246246
raise ValueError("invalid buffering size")
247247
if buffering == 0:

Modules/_io/_iomodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
367367
if (blksize_obj == NULL)
368368
goto error;
369369
buffering = PyLong_AsLong(blksize_obj);
370+
if (buffering > 8192 * 1024)
371+
{
372+
buffering = 8192 * 1024;
373+
}
370374
if (buffering < DEFAULT_BUFFER_SIZE)
371375
{
372376
buffering = DEFAULT_BUFFER_SIZE;

0 commit comments

Comments
 (0)