Skip to content

ImageFileReader accepts invalid frame indices #449

Closed

Description

@yinkev

Describe the bug

ImageFileReader.read_frame_raw() uses index > number_of_frames as its bounds check. This allows negative Python indexing and also misses the first invalid upper-bound value, index == number_of_frames.

To reproduce

Open any multiframe image and call:

reader.read_frame_raw(-1)
reader.read_frame_raw(reader.number_of_frames)

Current behavior: the negative index accesses the last offset-table entry, while the upper-bound case fails later through incidental indexing or I/O behavior.

Expected behavior

Valid indices should be exactly 0 <= index < number_of_frames. Invalid indices should raise a clear ValueError before indexing the offset table or seeking into pixel data. read_frame() should inherit the same contract.

Scope

Correct the bounds predicate, document the exception, and add lower- and upper-bound regressions.

Process note

I am filing this issue before the replacement pull request in accordance with the developer guide's issue-first recommendation. PR #434 was opened before that preflight and will be superseded.

Activity

  1. yinkev commented on Jul 25, 2026

    @yinkev
    ContributorAuthor

    Duplicate of #439. A parallel authorized remediation had already created the canonical issue-first record and compliant replacement PR before this batch completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions