Skip to content

Fix two issues with stb_image and HLSLParser - #1025

Open
kblaschke wants to merge 2 commits into
projectM-visualizer:masterfrom
kblaschke:bugfix/fix-some-errors
Open

Fix two issues with stb_image and HLSLParser#1025
kblaschke wants to merge 2 commits into
projectM-visualizer:masterfrom
kblaschke:bugfix/fix-some-errors

Conversation

@kblaschke

Copy link
Copy Markdown
Member

While testing, I ran into two issues, one crashing and another freezing projectM. Investigation resulted in this:

stb_image: Crash due to unchecked pointers

Some image decoders in stb_image - including the DDS loader - didn't check user-provide return variable pointers to be NULL before assignikng values. According to the API docs, these pointers can be NULL if the user isn't interested in the value.

I've added guards around the problematic assignments I've found.

HLSLParser: Infinite macro replacement loop

Loading some presets, e.g. martin + Se7enSlasher - pixies party (random texture edit).milk, resulted in a freeze of the application with quickly increasing memory usage. The reason was a macro in the HLSL code, which just pointed to itself: #define sampler_rand00 sampler_rand00. HLSLParser wrapped the value in parentheses and then ran the same code again, adding one set of parentheses per loop execution, indefinitely.

The fix now checks if the macro is simply a copy of itself, and keeps the original code in this case, without the need for another loop. Macros with arguments may still run into an infinite loop, but are harder to create and I haven't found any preset doing such a thing, as it would probably also fail in the original HLSL compiler.

@kblaschke kblaschke self-assigned this Sep 9, 2026
@kblaschke kblaschke added the bug The issue is (potentially) a bug. label Sep 9, 2026
@kblaschke kblaschke added this to the 4.2 milestone Sep 9, 2026
User-provided pointers for return values weren't checked in some image formats, specifically DDS. Since projectM doesn't pass a valid pointer for the channel count, this lead to a nullptr dereference when loading such textures.
One example affected preset is "martin + Se7enSlasher - pixies party (random texture edit).milk"

Macros with an argument referencing itself may still be problematic, but is WAY less probable to pop up in the wild.
@kblaschke
kblaschke force-pushed the bugfix/fix-some-errors branch from fb6d55c to 63aa39f Compare September 10, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue is (potentially) a bug.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant