You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to read the last 16 sectors from a Windows device through the Python file interface fails unexpectedly when buffering is enabled. Those same sectors seem to be accessible without issue through the WIN32 file API itself.
I've included minimal reproduction code. To demonstrate this, configure DEVICE_SECTOR_CNT and DEVICE_PATH to match a drive attached to your system:
Note that when I see this, the generated Errno is different for different devices. This could possibly be a bug in some Windows API that Python is relying on, but I'm not the one to determine that. If buffering is disabled in the Python file interface (by adding , 0 to the end of the open(...) call) then this issue does not occur, so my immediate suspicion is that the buffer implementation is reading past the end of the device for some reason.
This has been tested with Python 3.12.3 on Windows 11 10.0.22631
CPython versions tested on:
3.12
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered:
Most likely the buffering is assuming that the result will be a partial read when it reaches the end of the file/device.
I doubt there's anything sensible we can change here. We don't know that it's a device, or that it's going to behave strangely. Unless there's a flag we can pass for all types of files to make Windows do a partial read rather than return some error code (or if this is a unique error code - print out winerror on that exception to see what the OS returned), all we can really do is suggest disabling buffering.
Bug report
Bug description:
Attempting to read the last 16 sectors from a Windows device through the Python file interface fails unexpectedly when buffering is enabled. Those same sectors seem to be accessible without issue through the WIN32 file API itself.
I've included minimal reproduction code. To demonstrate this, configure
DEVICE_SECTOR_CNT
andDEVICE_PATH
to match a drive attached to your system:Testing this with any drive attached to my system, I see a result like:
Note that when I see this, the generated Errno is different for different devices. This could possibly be a bug in some Windows API that Python is relying on, but I'm not the one to determine that. If buffering is disabled in the Python file interface (by adding
, 0
to the end of theopen(...)
call) then this issue does not occur, so my immediate suspicion is that the buffer implementation is reading past the end of the device for some reason.This has been tested with Python 3.12.3 on Windows 11 10.0.22631
CPython versions tested on:
3.12
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: