File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -452,6 +452,11 @@ def test_readinto(self):
452452 self .assertEqual (a .tobytes (), b"1234567890d" )
453453 memio .close ()
454454 self .assertRaises (ValueError , memio .readinto , b )
455+ memio = self .ioclass (b"123" )
456+ b = bytearray ()
457+ memio .seek (42 )
458+ memio .readinto (b )
459+ self .assertEqual (b , b"" )
455460
456461 def test_relative_seek (self ):
457462 buf = self .buftype ("1234567890" )
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ Core and Builtins
2424Library
2525-------
2626
27+ - Issue #10467: Fix BytesIO.readinto() after seeking into a position after the
28+ end of the file.
29+
2730- Issue #1682942: configparser supports alternative option/value delimiters.
2831
2932- Issue #5412: configparser supports mapping protocol access.
Original file line number Diff line number Diff line change @@ -430,15 +430,20 @@ static PyObject *
430430bytesio_readinto (bytesio * self , PyObject * buffer )
431431{
432432 void * raw_buffer ;
433- Py_ssize_t len ;
433+ Py_ssize_t len , n ;
434434
435435 CHECK_CLOSED (self );
436436
437437 if (PyObject_AsWriteBuffer (buffer , & raw_buffer , & len ) == -1 )
438438 return NULL ;
439439
440- if (self -> pos + len > self -> string_size )
441- len = self -> string_size - self -> pos ;
440+ /* adjust invalid sizes */
441+ n = self -> string_size - self -> pos ;
442+ if (len > n ) {
443+ len = n ;
444+ if (len < 0 )
445+ len = 0 ;
446+ }
442447
443448 memcpy (raw_buffer , self -> buf + self -> pos , len );
444449 assert (self -> pos + len < PY_SSIZE_T_MAX );
You can’t perform that action at this time.
0 commit comments