You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(py): reject non-RGBA images before native calls - #780
Added validation to the shared Python wrapper to require image arrays shaped (H, W, 4). Invalid channel layouts now raise a clear ValueError before reaching native image functions.
Reason
The native code expects RGBA input. Grayscale arrays could otherwise cause buffer overreads and crash the Python process.
Reviewing files that changed from the base of the PR and between 67e5e60 and 6fc9ae6.
📒 Files selected for processing: 1
packages/py/img2num/api.py
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
_inject_dimensions now accepts only RGBA image arrays with shape (H, W, 4).
Invalid shapes raise ValueError before the wrapped native function is called.
The author reports that the smoke check, py_compile, and git diff --check passed. The full native package integration test was not run.
Author
Lines added
Lines removed
krishna2707
2
2
Walkthrough
The Python API now requires image inputs to have three dimensions and four channels. _inject_dimensions raises ValueError for inputs that do not meet this shape requirement.
Changes
Image Input Validation
Layer / File(s)
Summary
Validate image shape packages/py/img2num/api.py
_inject_dimensions now rejects inputs unless they have shape (H, W, 4).
The PR adds pre-native shape validation for non-RGBA inputs. Other dtypes are already rejected by the typed bindings, leaving no material merge risk evident in the supplied context.
Pre-merge checks: 6 · 2
Failed checks: 2 warnings
Check name
Status
Explanation
Resolution
Linked Issues check
Issue #772 requires rejection of inputs that do not use the documented four-channel uint8 RGBA format. The change correctly rejects arrays whose shape is not exactly (H, W, 4) before the wrapped nat…
Add a dtype check for np.uint8 in _inject_dimensions and raise the documented clear Python exception before the native wrapper is called. Add an automated test for a non-uint8 (H, W, 4) array.
Docstring Coverage
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files.
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 6 passed
Check name
Status
Explanation
Out of Scope Changes check
The pull request changes only the shared Python image validation in packages/py/img2num/api.py. Shape validation for the affected image APIs is directly connected to issue #772. No unrelated change …
No Ai Slop Pr Description
The description is specific to this PR. It explains the (H, W, 4) validation, the ValueError, the native-call safety reason, affected input cases, and reported verification. The diff confirms the …
No Strangely-Named Root Markdown Files
The pull request changes only packages/py/img2num/api.py. It adds no files at the repository root, so it does not add any unconventional root Markdown file.
Coderabbit Config Needs Update
PASS. The PR changes only packages/py/img2num/api.py. The base .coderabbit.yaml already contains reviews.path_instructions for **/*.py, and Python tooling is configured (ruff and pylint). …
Title check
The title uses the conventional fix(py): prefix and clearly describes rejecting non-RGBA images before native calls.
Description check
The description directly explains the RGBA validation change, its safety reason, testing, and related issue.
Full details: Out of Scope Changes check
Explanation
The pull request changes only the shared Python image validation in packages/py/img2num/api.py. Shape validation for the affected image APIs is directly connected to issue #772. No unrelated change is shown.
Full details: No Ai Slop Pr Description
Explanation
The description is specific to this PR. It explains the (H, W, 4) validation, the ValueError, the native-call safety reason, affected input cases, and reported verification. The diff confirms the described change in packages/py/img2num/api.py; no generic AI boilerplate appears.
Full details: Coderabbit Config Needs Update
Explanation
PASS. The PR changes only packages/py/img2num/api.py. The base .coderabbit.yaml already contains reviews.path_instructions for **/*.py, and Python tooling is configured (ruff and pylint). The diff adds no linter/formatter config, CI/tooling config, or uncovered file extension.
Full details: Linked Issues check
Explanation
Issue #772 requires rejection of inputs that do not use the documented four-channel uint8 RGBA format. The change correctly rejects arrays whose shape is not exactly (H, W, 4) before the wrapped native call. It does not validate image.dtype, so a non-uint8 array with shape (H, W, 4) is not rejected by the shared wrapper. The reported smoke check covers channel layouts and rank, but it does not establish dtype rejection.
Resolution
Add a dtype check for np.uint8 in _inject_dimensions and raise the documented clear Python exception before the native wrapper is called. Add an automated test for a non-uint8 (H, W, 4) array.
Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
✨ Simplify code
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks each pixel’s place Four channels pass the shape-bound gate Two dimensions now raise an error Three make the image shape appear The rabbit hops along its way
Comment @coderabbitai help to get the list of available commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes & Reason
Changes
Added validation to the shared Python wrapper to require image arrays shaped
(H, W, 4). Invalid channel layouts now raise a clearValueErrorbefore reaching native image functions.Reason
The native code expects RGBA input. Grayscale arrays could otherwise cause buffer overreads and crash the Python process.
Related Issues
Fixes: #772
Testing & Verification
ValueError.py_compilepassed.git diff --checkpassed.Additional Resources
None