This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cotton.seed
Recipients cotton.seed
Date 2021-01-26.05:29:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1611638952.77.0.560549779185.issue43028@roundup.psfhosted.org>
In-reply-to
Content
Seeking past the end of a file with file objects does not match the same code implemented in terms of file descriptors.  Is this the intended behavior?

Smallest example I could find:

f = open('new_file', 'ab')
print(f.seek(1))
print(f.write(b'foo'))
print(f.tell())
f.close()

This program outputs: 1, 3, 4 as expected, but only creates a 3-byte file:

and creates a 3-byte file:
$ hexdump -C new_file
00000000  66 6f 6f                                          |foo|
00000003

If I use open(..., buffering=0), or flush before the tell, it outputs: 1, 3, 3.

The obvious code with file descriptors:

fd = os.open('log', os.O_WRONLY | os.O_CREAT)
print(os.lseek(fd, 1, os.SEEK_SET))
os.write(fd, b'foo')
os.close(fd)

works as expected, creating a 4-byte file.

Could this be related this issue:

https://bugs.python.org/issue36411

?
History
Date User Action Args
2021-01-26 05:29:12cotton.seedsetrecipients: + cotton.seed
2021-01-26 05:29:12cotton.seedsetmessageid: <1611638952.77.0.560549779185.issue43028@roundup.psfhosted.org>
2021-01-26 05:29:12cotton.seedlinkissue43028 messages
2021-01-26 05:29:12cotton.seedcreate