Skip to content

[WASM] GL ES call to GetProgramInfoLog may throw unexpectedly #2594

Description

@paralaxsd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions