Open jhbruhn opened 1 year ago
I suppose that pattern was dropped. Inner implementation of color is
So there's pointer to const array, temp value on stack. I'll test, but could you try make it static or store anywhere?
There's almost same implementation but with lifetime and ownership.
Yikes! 😳
Yes, this is a use-after-free. LCDColor::Pattern(GRAY_PATTERN)
is constructed on the stack and dropped after from
returns: https://github.com/pd-rs/crankstart/blob/5b289e55598af9b90ceda3e24dff354815171ea2/src/graphics.rs#L36-L46
The implementation in @boozook's crate (owned variant) has the same problem for the same reason. The return value from from()
points at dropped memory.
From what I can tell, the PatternRef
variant in the linked crate is sound.
Agreed. This is next in my queue.
Any suggestions?
I have no good idea yet, just allow to store only &'static
pattern in the LCDColor::Pattern
(e.g.).
Also maybe allow something with !Unpin
🤷🏻♂️
I'll look at it tomorrow. Here is deep night now.
Also there is problem with bitmap.set_color_to_pattern
.
color
bitmap
bitmap.set_color_to_pattern(&mut color)
(or something like that)bitmap
Color, as we know, is ptr points to array allocated somewhere.
And it isn't changed at step 4! Seems to it's our own array from now.
So when it should be feed? What padding, what preserved capacity?Update: No, if try to free it => SIGSEGV in sim. Not tested on the device.
I believe any lifetime will work. It just might be a bit of an ergonomics issue for users. I tested this yesterday with MIRI and it seemed ok (apart from the int-pointer casts, which raised some warnings).
(edit: this is not in reference to bitmap.set_color_to_pattern
)
Do I take it that the assignment means you want (one of us) to submit a PR for this issue?
It with be great. Of course, no pressure, just say no if you don't want to. The assignment is just a hint to attract attention.
There seems to be a bug in the LCDPattern implementation. When using the
draw_line
method (and possibly others), the Pattern is drawn with random data (changes for example on button inputs) instead of the selected pattern (in my case a checkerboard for grayscale).This was only tested on the simulator though, as I don't have real hardware yet!
Here is an example. The leftmost line should have every second pixel on, but it's actually even more (and changes in more complex programs). The second line is supposed to be solid.