-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Displayio Bitmap arg validation #7548
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
Conversation
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.
In displayio_bitmap_obj_blit
, the use of int16_t
truncates the high bits of the input. So if the caller passed 65,537, it would actually get interpreted as 1. You should probably replace all these occurences with int32_t
or mp_int_t
.
I wonder if we could use the arg_check_max function to limit the valid values that can be passed rather than using a larger int size to accommodate the larger values. I think it's possible a that it wouldn't be able to successfully operate on a Bitmap of that size for other reasons as well. |
There's already range checking code on lines 242-52. |
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.
Happy to see someone work on this. I think it can be better still, though.
the latest commits contain a change that uses the arg validation functions and removes the seperate logic check. This limits the bounds to a smaller number to get rid of the issue of it going over the max and wrapping around as well as consolidates the check into a single place when it first saves the argument. |
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.
Thanks. Sadly, we're going to have to do one more iteration of this.
I was wrong when I stated that this was a correct way to get the maximum value, including for 32-bit bitmaps:
(1u << common_hal_displayio_bitmap_get_bits_per_value(self)) - 1
we'll need to define a function to return the maximum bitmap value and then call it in these cases. It'll apparently need a special case for 32-bit bitmaps.
:-/
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.
(see previous comment, I suggested something that was not correct)
This seems to be correct without any special cases: |
Thank you! The latest commit changes the maximum value computation to use the new one that you mentioned. I tested it successfully with this change on a Feather ESP32S2 TFT with both upper and lower bounds for the value input. |
# Conflicts: # shared-bindings/displayio/Palette.c
This had some conflicts in Palette.c, I merged from main and resolved them. |
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.
It looks to me like the remaining points have been addressed. Thanks @FoamyGuy and reviewers.
@jepler Do you have time to re-review? |
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.
thanks
FYI this breaks turtle because it changes subscr errors from IndexError to ValueError. I'll look at fixing this. |
This change includes validation for arguments to Bitmap constructor,
fill()
,__get_item__
and__set_item__
to raise errors if users pass in negative values for things that can't really be negative.This resolves: #7540 as well as a few similar issues on other functions and properties in Bitmap class