Skip to content

Commit 8bf4087

Browse files
ashketchumwasherearcady-lunarg
authored andcommitted
preprocessor: guard against column underflow in DoPreprocessing
When DoPreprocessing::operator() encounters a new line, it attempts to emit leading whitespace via: outputBuffer += std::string(ppToken.loc.column - 1, ' '); If ppToken.loc.column is 0 (which can occur after a backslash-newline continuation at the end of input, e.g. 'GL_EXT_shader_image_load_formatted\\n' with GLSL version 450 and EShMsgDefault), the subtraction underflows to SIZE_MAX, causing std::string(SIZE_MAX, ' ') to throw std::length_error. Since the exception is uncaught, std::terminate() is called and the process aborts. Fix: add a column > 0 guard before the subtraction. Reproducer (36 bytes, pure ASCII): GL_EXT_shader_image_load_formatted\\n → TShader::preprocess(version=450, ENoProfile, EShMsgDefault) → terminate called after throwing 'std::length_error': basic_string::_M_create
1 parent a163b7f commit 8bf4087

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

glslang/MachineIndependent/ShaderLang.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,8 @@ struct DoPreprocessing {
11781178
// Don't emit whitespace onto empty lines.
11791179
// Copy any whitespace characters at the start of a line
11801180
// from the input to the output.
1181-
outputBuffer += std::string(ppToken.loc.column - 1, ' ');
1181+
if (ppToken.loc.column > 0)
1182+
outputBuffer += std::string(ppToken.loc.column - 1, ' ');
11821183
}
11831184

11841185
// Output a space in between tokens, but not at the start of a line,

0 commit comments

Comments
 (0)