Open godmar opened 10 months ago
I found the issue. ws2811_led_set
currently does not check for negative led indices:
int ws2811_led_set(ws2811_channel_t *channel, int lednum, uint32_t color)
{
if (lednum >= channel->count)
{
return -1;
}
channel->leds[lednum] = color;
return 0;
}
A negative value for lednum
will not be caught and leads to memory corruption.
Even though this library is close to the hardware, it would be nice if the Python wrapper were memory safe and would catch this kind of bug in a fail-safe manner.
IMO, it may even be advisable to turn it into an IndexError
(or implement Python's negative index semantics), rather than returning -1 (which the caller may not check). PixelStrip
appears to want to act like an array, but doesn't implement negative indices either.
Leaving this open for comment.
I'm using rpi-ws281x 5.0.0 on an RPi 3b with Raspbian GNU/Linux 11. My Python program does not use any other native libraries besides this one. In my app, I'm using 2 PWM channels (GPIO 18 and 19) and one 1 PCM channel (GPIO 21), and the app/hardware basically works.
However, usually when exiting, the program crashes due to an attempt to free an invalid pointer in
ws2811_cleanup
:I'm not sure if this constitutes a problem with the Python wrapper or with
rpi_ws281x
itself. I haven't been able to collect more information, but I wanted to leave this bug report since this shouldn't happen.