Raylib: [textures] LoadImage(name) will crash if name does not contain a valid extension

Created on 11 Jan 2020  路  4Comments  路  Source: raysan5/raylib

Please, before submitting a new issue verify and check:

  • [X] I tested it on latest raylib version from master branch
  • [X] I checked there is no similar issue already reported
  • [X] My code has no errors or misuse of raylib

Issue description

  • When passing a filename to LoadImage, if the extension is omitted (for various reasons this could apply), Raylib will ultimately crash at TextToLower() with a null pointer.

    Code Example

Image myimage = LoadImage("myfile");

All 4 comments

Hi

In version 2.5 I have this WARNING and I find no problem.

WARNING: Image file format [myfile] is not supported
WARNING: [myfile] Image could not be loaded

Hi

In version 2.5 I have this WARNING and I find no problem.

WARNING: Image file format [myfile] is not supported
WARNING: [myfile] Image could not be loaded

Just always check the null result.

Can you please try to replicate this with latest raylib version from master branch as I have done (and as is required by the issue submission process).

This could be my error (possible) but could also be a regression (possible).

It could also be a platform specific thing, but in my example, i do not even get a return from loadImage to check for a null result.

I will check again though 馃檭

Having checked, it is raylib/core.c at fault, not me.

line 1835 of core.c :

bool result = false;
    const char *fileExt = GetExtension(fileName); // <-- GetExtension returns NULL here
    char fileExtLower[16] = { 0 };

    strcpy(fileExtLower, TextToLower(fileExt)); // TextToLower crashes here as explained in the issue report

fileExt is null at this point and is not being checked.

Was this page helpful?
0 / 5 - 0 ratings