soil icon indicating copy to clipboard operation
soil copied to clipboard

NULL pointer dereference on integrated GPU

Open nikitkagood opened this issue 4 years ago • 3 comments

Hi, I have my little OpenGL project that uses SOIL. On my home PC with RX 580 it runs just fine. On my working PC with i7-9700 and Intel UHD Graphics 630 there is an error in function query_NPOT_capability(void), line strstr( (char const*)glGetString( GL_EXTENSIONS ), "GL_ARB_texture_non_power_of_two" ) ). Because (char const*)glGetString( GL_EXTENSIONS ) returns null pointer and strstr tries to dereference it.

Why do I think this is an integrated GPU issue? Well, can't say for sure. I've seen assumptions of it on the internet. Then I made an experiment which kinda proved it.

I also made a simple fix by adding NULL check.

nikitkagood avatar Oct 04 '21 09:10 nikitkagood

The issue is still not fixed. jwerle has not implemented the simple NULL check. And now I'm the one getting segfault at the strstr() call in soil.c:1903

__strstr_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S:40
40      ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S: No such file or directory.
(gdb) bt
#0  __strstr_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S:40
#1  0x00007ffff798477d in query_NPOT_capability () from /usr/lib/libSOIL.so.1
#2  0x00007ffff7984b4d in SOIL_internal_create_OGL_texture () from /usr/lib/libSOIL.so.1
#3  0x00007ffff7986af0 in SOIL_load_OGL_texture () from /usr/lib/libSOIL.so.1
#4  0x0000555555573a81 in loadEarthTexture (path="/usr/local/share/arftracksat/earth.png") at /home/arf20/sources/arftracksat/representation/asset_loader.cpp:60
#5  0x000055555559e380 in startGraphics (shownSats=std::vector of length 46, capacity 64 = {...}, sta=..., mapfile="/usr/local/share/arftracksat/map.json", texturefile="/usr/local/share/arftracksat/earth.png")
    at /home/arf20/sources/arftracksat/representation/graphics.cpp:321
#6  0x00005555555a2da6 in main (argc=1, argv=0x7fffffffdfd8) at /home/arf20/sources/arftracksat/src/main.cpp:200```

arf20 avatar Oct 14 '22 14:10 arf20

Hi everyone. I'm not sure whether arf20 comment implies I am ought to do something.

I haven't been working with OpenGL (and therefore with SOIL) for quite some time, so I'd rather choose to not dig into the problem too much. And I don't have integrated graphics for tests anymore anyway.

There is pull request from me even though it's not attached to the issue. It does implement fix (i.e the simple pointer NULL check) to my problem in function query_NPOT_capability. It shouldn't be too hard to make the same fix yourself. Just in another function (soil.c:1903 ->query_tex_rectangle_capability). And obviously to test it straight away.

I have to point out my fix might be a bit wrong. Cause if glGetString_extentions_ptr != NULL -> "capability none" and thus if ptr == NULL -> "capability present" (soil.c:1880), which probably has to be the other way around. But maybe I did it this way because "capability none" actually resulted in other problems.

If there is need for a simple solution.

Considering there are many simillar functions and glGetString everywhere and the docs say "If an error is generated, glGetString returns 0". There might be a deeper look required. I.e. catching the error before everything crashes and then looking into it. Previously I missed this part cause I was too newbie I guess.

But like I said I'd rather not write any code myself, sorry.

nikitkagood avatar Oct 15 '22 11:10 nikitkagood

I did not mean to annoy you, sorry. I forgot to mention that this is no longer an iGPU problem only, but I did post in this thread because it already mentions the culprit.

SOIL segfaults when using remote X11 servers such as VcXSrv on Windows.

While there is a pull request, and it is merged, I chose to use SOIL because it was already in the debian repository, which is not yet updated.

So I moved to use std_image.h instead. Thank you anyway.

arf20 avatar Oct 15 '22 12:10 arf20