Skip to content

glslc: escape special characters and reject newlines in depfiles (fixes #1600) - #1608

Open
jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-glslc-depfile-escaping-1600
Open

jdymitarai wants to merge 1 commit into
google:mainfrom
jdymitarai:fix-glslc-depfile-escaping-1600

Conversation

@jdymitarai

@jdymitarai jdymitarai commented Oct 10, 2026 •

Copy link
Copy Markdown

When generating dependency files via -M or -MD, glslc was outputting target names, source paths, and included headers without escaping GNU make special characters or validating for unrepresentable newlines. This allowed paths containing dollar signs to execute arbitrary subshells like $(shell ...) and allowed newlines to inject unintended make rules.

Following GCC munge() (libcpp/mkdeps.cc) and glslang writeEscapedDepString(), this change escapes $, space, tab, #, :, \, [, and ] in dependency targets and prerequisites, while rejecting unrepresentable newline and carriage return characters with a diagnostic error.

We have added comprehensive unit tests covering character escaping and newline rejection in glslc_dependency_info_test, along with end-to-end regression tests in option_dash_M.py. All 25 glslc and shaderc test suites pass cleanly.

…fixes google#1600)

Signed-off-by: jdymitarai <o10040115@gmail.com>

@dneto0 dneto0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the the thorough tests. It made it much easier to review!

break;
case ' ':
case '\t':
out << "\\ ";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why does a tab not map to an escaped-tab?

This is inconsistent with glslang's escaping logic, which doesn't handle tabs specially.

On the other hand the munge() function is also quite different, and its comment says it's not possible to do a perfect job.

TEST(DependencyInfoEscapeTest, TabEscapedAsWhitespace) {
std::string escaped;
EXPECT_TRUE(EscapeDepPath("path\twith\ttabs.vert", &escaped));
EXPECT_EQ("path\\ with\\ tabs.vert", escaped);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As I commented in the feature code, this surprises me. But in any case this overall patch improves the situation.

@dneto0
dneto0 enabled auto-merge (rebase) October 19, 2026 19:11
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.

3 participants