NVIDIA-AI-IOT / NVIDIA-AI-IOT/deepstream_libraries

`SimpleDecoder.__getitem__` incorrectly validates exclusive [stop] of Python slice

Open
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
90
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Library version: PyNvVideoCodec 2.1.0 (pip, pynvvideocodec==2.1.0)

Bug:
SimpleDecoder.__getitem__ calls self.validate_index(key.stop) on the exclusive stop of a Python slice. This raises IndexError when stop == len(decoder), which is the normal Python convention for "all remaining elements."

Location: SimpleDecoder.py, lines 88–94

elif isinstance(key, slice):
    indices = range(key.start, key.stop, key.step)  # stop is exclusive here ✓
    idxs = list(iter(indices))
    if not idxs:
        raise ValueError(f"Invalid input.")
    self.validate_index(key.start)
    self.validate_index(key.stop)      # ← BUG: validates exclusive stop as if inclusive
    return self.simple_decoder[idxs]

Reproduce:

import PyNvVideoCodec as nvc

dec = nvc.SimpleDecoder("any_video.mp4", output_color_type=nvc.OutputColorType.RGB)
n = len(dec)       # e.g. 107
frames = dec[0:n:1]  # IndexError: Index 107 is out of range [0, 106]

Expected: dec[0:n:1] should return all n frames, consistent with standard Python slice semantics where stop is exclusive.

Fix:
self.validate_index(key.stop - 1). Also, I'd probably move the self.validate(key.start) and self.validate(key.stop) before the whole range to list to reduce unnecessary computation before you know the range is safe.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in SimpleDecoder.py at lines 88–94 and inspect how slice bounds are validated after building idxs. Reproduce the issue with dec[0:len(dec):1], then verify that the exclusive stop at len(dec) returns all frames without IndexError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.