Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.12] gh-95782: Fix io.BufferedReader.tell() etc. being able to return offsets < 0 (GH-99709)#115599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@miss-islington
Copy link
Contributor

@miss-islingtonmiss-islington commentedFeb 17, 2024
edited by bedevere-appbot
Loading

lseek() always returns 0 for character pseudo-devices like
/dev/urandom (for other non-regular files, e.g./dev/stdin, it
always returns -1, to which CPython reacts by raising appropriate
exceptions). They are thus technically seekable despite not having seek
semantics.

When calling read() on e.g. an instance ofio.BufferedReader that
wraps such a file,BufferedReader reads ahead, filling its buffer,
creating a discrepancy between the number of bytes read and the internal
tell() always returning 0, which previously resulted in e.g.
BufferedReader.tell() orBufferedReader.seek() being able to return
positions < 0 even though these are supposed to be always >= 0.

Invariably keep the return value non-negative by returning
max(former_return_value, 0) instead, and add some corresponding tests.
(cherry picked from commit26800cf)

Co-authored-by: 6t8k58048945+6t8k@users.noreply.github.com

…n offsets < 0 (pythonGH-99709)lseek() always returns 0 for character pseudo-devices like`/dev/urandom` (for other non-regular files, e.g. `/dev/stdin`, italways returns -1, to which CPython reacts by raising appropriateexceptions). They are thus technically seekable despite not having seeksemantics.When calling read() on e.g. an instance of `io.BufferedReader` thatwraps such a file, `BufferedReader` reads ahead, filling its buffer,creating a discrepancy between the number of bytes read and the internal`tell()` always returning 0, which previously resulted in e.g.`BufferedReader.tell()` or `BufferedReader.seek()` being able to returnpositions < 0 even though these are supposed to be always >= 0.Invariably keep the return value non-negative by returningmax(former_return_value, 0) instead, and add some corresponding tests.(cherry picked from commit26800cf)Co-authored-by: 6t8k <58048945+6t8k@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@miss-islington@serhiy-storchaka@6t8k

[8]ページ先頭

©2009-2025 Movatter.jp