Skip to content

hashlib.file_digest does not honor current position for io.BytesIO inputs #155419

Open

Description

@picnixz

Bug report

Bug description:

hashlib.file_digest() takes a getbuffer() fast path that hashes the entire buffer regardless of tell(), so the same bytes at the same position give a different digest for io.BytesIO than for a real binary file.

We never had tests to exercise that behavior and we never got report about it. I want to sync the merges of all PRs at once so that the behavior is fixed simultaneously before the next release.

cc @gpshead @hugovk

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Aug 9, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 9, 2026
  3. self-assigned this
    on Aug 9, 2026
  4. picnixz commented on Aug 9, 2026

    @picnixz
    MemberAuthor

    I decided to fix this instead of document the inconsistency because when not given a io.BytesIO object, we are actually honoring the position. So it's a bug.

  5. added 3 commits that reference this issue on Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions