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
@StanFromIreland , Thanks, I reproduced this issue, and I think the assertion failure occurs because the tell() method's optimization algorithm assumes there's buffered input data to search through, but when a file ends with a standalone carriage return (\r), an empty snapshot buffer gets created. The algorithm calculates that it needs to skip some bytes based on the character-to-byte ratio, then tries to navigate within the buffer using a binary search approach, but fails when skip_back=1 exceeds the buffer size of 0. I think the cleanest fix is to detect when next_input is empty and skip the optimization phase entirely, letting the algorithm fall back to the precise byte-by-byte decoding method, which always works correctly. I can open the PR if this seems correct.
Happy for others to work on, planning to look at myself no earlier than next Tuesday. I've mainly been focusing on BufferdIO which sits below TextIO so not sure the likely code changes needed here.
Activity
StanFromIreland commentedon Nov 9, 2025
Smaller repro:
mohsinm-dev commentedon Nov 9, 2025
@StanFromIreland , Thanks, I reproduced this issue, and I think the assertion failure occurs because the tell() method's optimization algorithm assumes there's buffered input data to search through, but when a file ends with a standalone carriage return (\r), an empty snapshot buffer gets created. The algorithm calculates that it needs to skip some bytes based on the character-to-byte ratio, then tries to navigate within the buffer using a binary search approach, but fails when skip_back=1 exceeds the buffer size of 0. I think the cleanest fix is to detect when next_input is empty and skip the optimization phase entirely, letting the algorithm fall back to the precise byte-by-byte decoding method, which always works correctly. I can open the PR if this seems correct.
ZeroIntensity commentedon Nov 10, 2025
cc @cmaloney
cmaloney commentedon Nov 10, 2025
Happy for others to work on, planning to look at myself no earlier than next Tuesday. I've mainly been focusing on BufferdIO which sits below TextIO so not sure the likely code changes needed here.
yihong0618 commentedon Nov 10, 2025
more info:
gdb backtrace
pythongh-141314: Fix TextIOWrapper.tell() assertion failure with stan…
pythongh-141314: Fix TextIOWrapper.tell() assertion failure with stan…
gh-141314: Fix TextIOWrapper.tell() assertion failure with standalone…
[3.14] pythongh-141314: Fix TextIOWrapper.tell() assertion failure wi…
[3.14] gh-141314: Fix TextIOWrapper.tell() assertion failure with sta…
[3.13] gh-141314: Fix TextIOWrapper.tell() assertion failure with sta…
pythongh-141314: Fix TextIOWrapper.tell() assertion failure with stan…