PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.16k stars 1.23k forks source link

PXR_AR_DISABLE_PLUGIN_RESOLVER raises Undefined behavior #3079

Open DADA246c opened 6 months ago

DADA246c commented 6 months ago

Description of Issue

in _GetAvailablePrimaryResolvers() https://github.com/PixarAnimationStudios/OpenUSD/blob/2864f3d04f396432f22ec5d6928fc37d34bb4c90/pxr/usd/ar/resolver.cpp#L313

If PXR_AR_DISABLE_PLUGIN_RESOLVER is set, allAvailableResolvers uses emptyResolverList and availablePrimaryResolvers will be empty vector.

in TF_VERIFY(availablePrimaryResolvers.back().type == defaultResolverType); https://github.com/PixarAnimationStudios/OpenUSD/blob/2864f3d04f396432f22ec5d6928fc37d34bb4c90/pxr/usd/ar/resolver.cpp#L347C5-L347C77

std::vector::back raises undefined behavior when the vector is empty (https://en.cppreference.com/w/cpp/container/vector/back)

in MSVC on Windows https://github.com/microsoft/STL/blob/8dc4faadafb52e3e0a627e046b41258032d9bc6a/stl/inc/vector#L1945 std::vector::back call _STL_VERIFY , the program will be aborted.

Steps to Reproduce

  1. set PXR_AR_DISABLE_PLUGIN_RESOLVER
  2. call pxr::UsdStage::Open()

System Information (OS, Hardware)

Windows 11

Compiler Visual Studio 2022 17.9.6

Package Versions

OpenUSD 24.05

Build Flags

--no-tutorials --no-examples --build-monolithic --build-variant debug

jesschimein commented 6 months ago

Filed as internal issue #USD-9654