libshaderc_util: make DecodeLineDirective robust to a non-canonical #line prefix#1578
Closed
adilburaksen wants to merge 1 commit into
Closed
libshaderc_util: make DecodeLineDirective robust to a non-canonical #line prefix#1578adilburaksen wants to merge 1 commit into
adilburaksen wants to merge 1 commit into
Conversation
…refix GetShaderStageFromSourceCode checks for the "#line" prefix (five characters, without the trailing space) before calling DecodeLineDirective, whose local kLineDirective is "#line " (six characters) and which does substr(kLineDirective.size()). The precondition that the argument is a canonical "#line " directive was enforced only by an assert, which is compiled out in release builds, so a line equal to exactly "#line" would make string_piece::substr advance past the end of the piece. Verify the full canonical prefix at runtime and return early otherwise, so the release behavior matches the documented precondition regardless of the caller.
Collaborator
|
Thanks for finding this! The real underyling problem is that there are two definitions of kLineDirective and they are out of sync. I'll fix this another way. |
dneto0
added a commit
that referenced
this pull request
Jul 8, 2026
Thanks to the implied bug report in #1578
Collaborator
|
Fixed by #1579 instead |
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.
Description
Compiler::GetShaderStageFromSourceCodeguards withstarts_with("#line")— fivecharacters, no trailing space (
kLineDirective = "#line") — and then callsDecodeLineDirective, whose own localkLineDirectiveis"#line "(six characters)and which does
directive.substr(kLineDirective.size())==substr(6).DecodeLineDirective's documented precondition (a canonicalized#linedirective) isenforced only by
assert(directive.starts_with(kLineDirective)), which is compiled outunder
NDEBUG. A line equal to exactly"#line"(five characters) passes the caller'sfive-character check but is one character shorter than the six the callee consumes, so in
a release build
string_piece::substr(6)produces a piece whosebegin_ > end_(its ownbound is likewise an assert), after which
size()underflows.This is latent in practice because glslang's preprocessor rejects a bare
#linebeforethis code runs, so it is not a reachable defect via shader input — but the helper should
not silently rely on that. This change verifies the full canonical prefix at runtime and
returns early otherwise, so the release behavior matches the precondition regardless of
the caller. No functional change for well-formed
#line <n>directives.