gh-150107: adding isinstance check on offset to include if available#150142
gh-150107: adding isinstance check on offset to include if available#150142grantlouisherman wants to merge 3 commits into
Conversation
…able Signed-off-by: grantlouisherman <grantlouisherman041@gmail.com>
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Hey @1st1 does this need a news blurb? IT seems pretty small |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Also I cant add the tags but this needs to be back ported to 3.12 and 3.13 |
Original Bug Report:
Bug report
Bug description:
BaseEventLoop._sock_sendfile_fallback(https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L971) erroneously doesn't seek when passed the offset 0.This check in the function doesn't call
file.seekif offset is falsey. If the file in question has a file pointer that is not currently at the 0 offset then this will erroneously send from the current offset and not the start of the file as desired. This can happen whensendfileis called with the destination socket is an SSL socket.Repro code (generated by Claude), because of needing to create an SSL socket it's a bit involved - including making a self signed cert with the openssl command.
The relevant lines are the line
f.seek(len(CONTENT))and the linesent = await loop.sendfile(writer.transport, f, offset=0). Most of the rest is setup and teardown.CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
Fix
I think what I did was correct or understood the issue, but essentially as far as I could understand
0is always falsey so if offset was ever set to zero than the file.seek wasent happening even though 0 offset is a legitimate offset. I simply just did an instance on offset to make sure it is an int and then the f.seek goes through. I validated with the repro command and passing unit tests.