NULL: fix uninitialised Window pointer read in getDepthBufferFor - #587
Merged
Merged
Conversation
The NULL window's colour texture carries TextureFlags::RenderWindowSpecific
but overrode no getCustomAttribute, and TextureGpu's base implementation is
an empty no-op. So in
if( colourTexture->isRenderWindowSpecific() )
{
Window *window; // uninitialised
colourTexture->getCustomAttribute( "Window", &window );
return window->getDepthBuffer();
}
(RenderSystem::getDepthBufferFor) the call left `window` holding whatever
the stack held, and the dereference read from that address.
Add NULLTextureGpuWindow, the NULL twin of MetalTextureGpuWindow /
VulkanTextureGpuWindow / D3D11TextureGpuWindow / GL3PlusTextureGpuWindow,
whose only job is to answer that attribute, and hand the window to
createTextureGpuWindow the way the other render systems do. The lookup then
returns the window's own depth buffer, which NULLWindow::_initialize has
been creating all along.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RenderSystem::getDepthBufferFor()reads an uninitialisedWindow *for every render-window pass under the NULL render system:NULLWindow::_initializecreates its colour texture withTextureFlags::RenderWindowSpecific, so the branch is taken — but no NULL texture class overridesgetCustomAttribute, andTextureGpu's base implementation is an empty no-op:The call therefore writes nothing,
windowkeeps whatever the stack slot held, and the next line dereferences it.Why it matters
This is not a cosmetic gap. Whether it crashes depends entirely on what happened to be on the stack: a Debug build can wander through and hand back a garbage
TextureGpu *that a compositor pass then uses, and a Release build of the same code segfaults (EXC_BAD_ACCESS). Anyone using the NULL RS for a headless/CI run hits it at the first pass targeting the window, in a build configuration where they cannot see why.Instrumented against master (the probe starts the local at a known poison value instead of relying on stack luck, and is otherwise a verbatim copy of what
getDepthBufferFordoes):The returned "depth buffer" is a value read out of unrelated memory.
The change
Add
NULLTextureGpuWindow, whose only job is to answer that attribute — the NULL twin ofMetalTextureGpuWindow,VulkanTextureGpuWindow,D3D11TextureGpuWindowandGL3PlusTextureGpuWindow, which all exist for exactly this — and pass the window tocreateTextureGpuWindow()the way the other render systems already do.Nothing else needed changing:
NULLWindow::_initializehas been creating a realmDepthBufferall along, so once the attribute is answered the lookup returns the window's own depth buffer.Verification
macOS 15 / Apple Silicon, clang,
RenderSystem_NULL+OgreNextMainbuilt static in Debug (the same probe as above, now checking the results instead of just printing them):getCustomAttributeleaves the caller's pointer untouched,getDepthBufferForreturns a value read from an unrelated address;getCustomAttribute("Window")returns the window, andgetDepthBufferForreturns exactlywindow->getDepthBuffer().Found while making the Ogre-Next backend of orkige run window-less and GPU-less for CI, which is the first thing that asked the NULL RS to service a render-window pass. There the Debug build happened to survive on a dereferenceable stack slot and the Release build of the same scene segfaulted at
0x28— which is how this was tracked down.