-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
UB: Bitmap::get_color_of_pattern
returns a dangling reference
#54
Comments
Thanks for the find and research! From headers in the SDK: typedef uint8_t LCDPattern[16]; // 8x8 pattern: 8 rows image data, 8 rows mask
typedef uintptr_t LCDColor; // LCDSolidColor or pointer to LCDPattern
Ok, we can wrap LCDPattern into newtype or enum with { PtrToLCDPattern, LCDPattern }. And so... 🤷🏻♂️ |
Ha! There is all wrong, seems to I've got it finally! |
@parasyte, |
LOL! Yeah, I like that solution. AFAICT, |
playdate/api/gfx/src/bitmap/bitmap.rs
Lines 302 to 313 in 30fc871
The
&mut LCDPattern
returned is not dependent on the lifetime of&self
, in fact it isn't dependent on any lifetime at all. The pointer is constructed from an integer. Running this code in MIRI (after stripping the sys API parts) reports:The
integer-pointer cast
warning suggests that the pointer may have been intended to be created from a reference tocolor
, but this also would not work! That would return a reference to a stack allocation. Short ofBitmap
owning some state that this method references, there is no way to return a loan like this.Another issue is the size disparity between
LCDColor
andLCDPattern
. Even if you did cast anLCDColor
reference to anLCDPattern
reference, that would result in out-of-bounds accesses.Probably what was intended is returning an owned
LCDColor
, which doesn't involve pointer casting shenanigans.The text was updated successfully, but these errors were encountered: