Skip to content

Reject out-of-range negative sampling starts - #1669

Closed
aswanth-07 wants to merge 1 commit into
meta-pytorch:mainfrom
aswanth-07:fix/reject-out-of-range-sampling-start
Closed

Reject out-of-range negative sampling starts#1669
aswanth-07 wants to merge 1 commit into
meta-pytorch:mainfrom
aswanth-07:fix/reject-out-of-range-sampling-start

Conversation

@aswanth-07

@aswanth-07 aswanth-07 commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Validate the lower bound of sampling_range_start before normalizing negative indices.

Root cause

Values below -len(decoder) were normalized to a still-negative frame index and could reach the index-based sampler/decoder path instead of being rejected as invalid input. The fix rejects those values while preserving the valid boundary at -len(decoder).

Verification

  • Added a regression case to the shared index-based sampler error suite, covering both public index-based samplers.
  • Passed py_compile for both changed Python files.
  • Passed the configured pre-commit hooks for both changed files.
  • Passed git diff --check.
  • A focused AST-level invariant check fails on the pristine source and passes with the patch, including the exact lower-bound and boundary cases.
  • Passed the full sampler test module with Python 3.13: 51 passed. The local wheel supplied the native video decoder; unavailable image decoders are not exercised by this module.
  • Scoped mypy reaches five existing errors in unrelated imported modules; the changed file adds no reported error.

Additional context

No open issue or pull request was found for this exact lower-bound case at the time of preparation. The validation follows the existing Python-style negative-index boundary: -len(decoder) is valid and smaller values are rejected before normalization.

AI assistance was used to prepare this draft. The submitter is responsible for reviewing, understanding, and defending every changed line. No CLA or other legal agreement has been accepted on the submitter's behalf.

@pytorch-bot

pytorch-bot Bot commented Aug 23, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1669

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 23, 2026
@aswanth-07
aswanth-07 marked this pull request as ready for review August 23, 2026 11:45
@aswanth-07

Copy link
Copy Markdown
Author

Closing this PR after audit. It adds a guard for an out-of-range sampling input without a user-reported issue or maintainer-confirmed contract. This needs an issue-first scope decision before a direct contribution. The source branch remains available.

@aswanth-07 aswanth-07 closed this Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant