[WASM] GL ES call to `GetProgramInfoLog` may throw unexpectedly

Open Beginner friendly
#2,594 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp, wasm

Research direction

Start by reproducing the failure with the linked SilkCrashRepro and then inspect Silk.NET.OpenGLES.GL.GetShaderInfoLog and the related string-overload implementations. Check each reported Substring length against the returned string, and consider the issue resolved when GetProgramInfoLog returns the linker log without throwing and the repeated patterns have been assessed.

Written by the indexing model from the issue text.

Description

bug

Summary

Retrieving the program info log on the browser-wasm platform may crash with ArgumentOutOfRangeException as a result of a string.Substring operation with mismatching length argument.

Steps to reproduce

  • Platform: browser-wasm
  • Framework: tested on DotNet 10.0
  • API: WebGL 2.0 + GL ES 3.0
  • Tested library version: Silk.Net.OpenGLES 2.23.0
  • IDE: tested with Visual Studio 2026 Community Edition (Insiders [11918.235])

I've prepared a repository that sets up a minimal crash repro. To trigger the crash, please clone the repository and perform the following steps:

  • Please ensure that WebAssembly build tools are installed as is described in the repo's Readme.md file.
  • Open the solution and press F5 to enter Debug mode.
  • Observe: the call to gl.GetProgramInfoLog(program) in SilkProgramInfoLogRepro.TryStringOverload throws rather than returning the info log detailing the program linker fault.
  • The span overload of GetProgramInfoLog? is not affected which can be shown by commenting the call to TryStringOverload and stepping through the subsequent function call in TrySpanOverload instead.

Comments

The symptom for this fault could be easily fixed by changing the implementation in Silk.NET.OpenGLES.GL.GetShaderInfoLog(uint shader, out string info) from

info = info.Substring(0, (int) length);

to something like

info = info.Substring(0, Math.Min((int)length, info.Length));

At this time I can only speculate why the length argument is returned to us with a value exceeding the info log's length. At some point it seemed as if a trailing '\n' character was trimmed from the end of the info log (the debugger stated that the string was changed) but I can't show this conclusively.

The GL type repeats this pattern of calling string.Substring with a given length a few more times. I do wonder if these could also be affected.

Dominant language
C#
Stars
5.2k
Forks
476
Avg merge
1d 20h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/Silk.NET

All issues in dotnet/Silk.NET

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.