Fix two issues with stb_image and HLSLParser - #1025
Open
kblaschke wants to merge 2 commits into
Open
Conversation
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
force-pushed
the
bugfix/fix-some-errors
branch
from
September 10, 2026 08:36
fb6d55c to
63aa39f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.