Skip to content

Fix off-by-one in 8266 DMA translation - #894

Merged
Makuna merged 3 commits into
Makuna:masterfrom
willmmiles:esp8266-dma-fix
Dec 1, 2025
Merged

Makuna merged 3 commits into
Makuna:masterfrom
willmmiles:esp8266-dma-fix

Conversation

@willmmiles

Copy link
Copy Markdown
Contributor

If the translated ESP8266 DMA buffer fit the source data size exactly, an extra write was being performed past the end of the buffer. This would typically overwrite the "block size" of the next allocation (or free area), resulting in heap corruption.

This patch ensures that the "end of loop" write is only performed if there's something to write.

willmmiles added a commit to willmmiles/WLED that referenced this pull request Dec 1, 2025
Shim in Makuna/NeoPixelBus#894 until approved by
upstream.  Fixes wled#4906 and wled#5136.
willmmiles added a commit to willmmiles/WLED that referenced this pull request Dec 1, 2025
Shim in Makuna/NeoPixelBus#894 until approved by
upstream.  Fixes wled#4906 and wled#5136.
@willmmiles

Copy link
Copy Markdown
Contributor Author

Ping - would you mind taking a look at this soon? We've just temporarily scrubbed a WLED release due to heap corruption caused by this problem. If there's anything I can do to improve this code or move this fix forward, please let me know.

@Makuna Makuna left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very minor change, In this code base, all branches no matter if one line must be braced and on separate lines. Also not comment update

        // store the remaining bits if any are left
        if (destBitsLeft != BitsInSample) 
        {
            *pDma++ = dmaValue;
        }

@willmmiles

Copy link
Copy Markdown
Contributor Author

Applied. I also noticed that the ESP32 driver that was an ancestor to the ESP8266 version appeared to be vulnerable to the same issue, so I applied the fix there, as well. Given that the logic is the same, should these instead be refactored to share an implementation?

@Makuna
Makuna merged commit a0919d1 into Makuna:master Dec 1, 2025
@Makuna

Makuna commented Dec 1, 2025

Copy link
Copy Markdown
Owner

Applied. I also noticed that the ESP32 driver that was an ancestor to the ESP8266 version appeared to be vulnerable to the same issue, so I applied the fix there, as well. Given that the logic is the same, should these instead be refactored to share an implementation?

There are newer branches for the future, Core3 is one. There is significant refactoring planned for the future. I wish I could find the time to finish it all. What I would really like is a solid contributor to take the new "design" and refactor it so WLED can clean up some other long-term issues they live with due to current designs. I can provide some overall design direction and reviews.

@willmmiles

Copy link
Copy Markdown
Contributor Author

Applied. I also noticed that the ESP32 driver that was an ancestor to the ESP8266 version appeared to be vulnerable to the same issue, so I applied the fix there, as well. Given that the logic is the same, should these instead be refactored to share an implementation?

There are newer branches for the future, Core3 is one. There is significant refactoring planned for the future. I wish I could find the time to finish it all. What I would really like is a solid contributor to take the new "design" and refactor it so WLED can clean up some other long-term issues they live with due to current designs. I can provide some overall design direction and reviews.

I can relate! There's always so much that can be done, never enough time, it seems. I'd love to hear more about the new design - what are the biggest pain points? What do you have in mind for future organization? I'd be happy to contribute where I can, but unfortunately I'm also not in a position to make a firm time commitment at the moment. Perhaps there's some room to make evolutionary steps that lead towards your new approach?

aenertia pushed a commit to aenertia/WLED that referenced this pull request Aug 18, 2026
Shim in Makuna/NeoPixelBus#894 until approved by
upstream.  Fixes wled#4906 and wled#5136.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants