-
Notifications
You must be signed in to change notification settings - Fork 11.2k
ui: fix crash of live cam on arch-linux #1602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
binarytrails
wants to merge
2
commits into
hacksider:main
Choose a base branch
from
binarytrails:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Ensure the dimensions are valid before attempting the resize operation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds robust validation of target and computed dimensions in fit_image_to_size to prevent invalid resize operations (e.g., zero or negative sizes) that can crash the live cam on some systems. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `modules/ui.py:769` </location>
<code_context>
def fit_image_to_size(image, width: int, height: int):
if width is None and height is None:
return image
+ if not isinstance(width, int) or not isinstance(height, int) or width <= 0 or height <= 0:
+ return image
h, w, _ = image.shape
</code_context>
<issue_to_address>
**suggestion:** The strict `int` type check may reject valid numeric types (e.g., NumPy integer scalars).
This check will be `False` for types like `numpy.int32`, so calls with common integer-like dimensions will unexpectedly return the original image. Consider using `numbers.Integral` (or a similar numeric protocol) instead of `int`, or relying on the `<= 0` guard and handling any type errors at the resize call, so valid integer-like widths/heights are accepted.
Suggested implementation:
```python
def fit_image_to_size(image, width: int, height: int):
if width is None and height is None:
return image
if not isinstance(width, numbers.Integral) or not isinstance(height, numbers.Integral) or width <= 0 or height <= 0:
return image
```
Add `import numbers` (or `from numbers import Integral` and adjust the checks accordingly) near the top of `modules/ui.py`, alongside the other imports:
- Option 1:
- `import numbers`
- keep `isinstance(width, numbers.Integral)` / `isinstance(height, numbers.Integral)`
- Option 2:
- `from numbers import Integral`
- change the checks to `isinstance(width, Integral)` / `isinstance(height, Integral)`
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Ensure the dimensions are valid before attempting the resize operation
Summary by Sourcery
Bug Fixes: