We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4047 - SDL_Vulkan_GetInstanceExtensions rejects an output array that is too large
Summary: SDL_Vulkan_GetInstanceExtensions rejects an output array that is too large
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.7
Hardware: All All
: P2 trivial
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-14 13:54 UTC by John Bartholomew
Modified: 2018-01-17 21:04 UTC (History)
0 users

See Also:


Attachments
Patch to allow GetInstanceExtensions output array larger than required (UNTESTED but simple) (956 bytes, patch)
2018-01-14 13:54 UTC, John Bartholomew
Details | Diff
Fixed patch to actually set *userCount as it should. (1.12 KB, patch)
2018-01-14 14:13 UTC, John Bartholomew
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Bartholomew 2018-01-14 13:54:58 UTC
Created attachment 3134 [details]
Patch to allow GetInstanceExtensions output array larger than required (UNTESTED but simple)

The doc comment for SDL_Vulkan_GetInstanceExtensions says:

 *  If \a pNames is \c NULL, then the number of required Vulkan instance
 *  extensions is returned in pCount. Otherwise, \a pCount must point to a
 *  variable set to the number of elements in the \a pNames array, and on
 *  return the variable is overwritten with the number of names actually
 *  written to \a pNames. If \a pCount is less than the number of required
 *  extensions, at most \a pCount structures will be written. If \a pCount
 *  is smaller than the number of required extensions, \c SDL_FALSE will be
 *  returned instead of \c SDL_TRUE, to indicate that not all the required
 *  extensions were returned.

But the code actually returns false not just if *pCount is smaller than required, but also if it is *larger* than required. In particular, this call pattern fails:

    const char *names[16] = {};  // Big enough for most purposes.
    unsigned int count = 16;
    if (!SDL_Vulkan_GetInstanceExtensions(window, &count, names)) {
      abort();
    }
    // ...

This fails even though 16 is far more than the number of required extensions because the code (SDL_Vulkan_GetInstanceExtensions_Helper) does:

    if(*userCount != nameCount)
    {
        SDL_SetError(
            "Count doesn't match count from previous call of SDL_Vulkan_GetInstanceExtensions");
        return SDL_FALSE;
    }

(userCount is pCount, nameCount is the number of extensions that need to be stored in the array)
Comment 1 John Bartholomew 2018-01-14 14:13:33 UTC
Created attachment 3139 [details]
Fixed patch to actually set *userCount as it should.

And of course despite being simple I messed up the first attempt at a fix.
Comment 2 Sam Lantinga 2018-01-17 21:04:12 UTC
Added, thanks!
https://hg.libsdl.org/SDL/rev/922c27f2fa56