KhronosGroup / KhronosGroup/glslang
#include does not handle absolute paths correctly
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
The following shader does not compile, despite the included file existing:
```glsl
#include "C:\users\Admin\Desktop\file.glsl"
void main(){}
```
This is because quoted includes get passed to `readLocalPath`, which assumes the path is local and transforms it before trying to read it:
https://github.com/KhronosGroup/glslang/blob/1cad045cc2bf79c976e1d7001ac71644f6cb29a8/StandAlone/DirStackFileIncluder.h#L103-L124
I fixed this in my copy by changing `readLocalPath` to check `headerName` as-is, in case it's an absolute path, before transforming it as a local path:
```cpp
virtual IncludeResult* readLocalPath(const char* headerName, const char* includerName, int depth)
{
// first check for absolute paths:
std::ifstream file(headerName, std::ios_base::binary | std::ios_base::ate);
if (file) {
directoryStack.push_back(getDirectory(headerName));
includedFiles.insert(headerName);
return newIncludeResult(headerName, file, (int)file.tellg());
}
// Discard popped include directories, and
// ...
```
Contributor guide
Research direction
Start in StandAlone/DirStackFileIncluder.h at readLocalPath, which currently transforms quoted include paths before reading them. Verify the behavior with the GLSL shader and absolute Windows path shown in the issue; done means the existing file is included and the shader compiles without breaking local includes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100