Skip to content

Commit

Permalink
[sdf, usd] Fix crash when URL-encoded characters are used to generate…
Browse files Browse the repository at this point in the history
… session layer identifiers.
  • Loading branch information
asluk authored and pixar-oss committed Oct 21, 2022
1 parent c99bb1b commit 5cd971b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pxr/usd/sdf/assetPathResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,12 @@ Sdf_GetAnonLayerIdentifierTemplate(
const string& tag)
{
string idTag = tag.empty() ? tag : TfStringTrim(tag);

// Ensure that URL-encoded characters are not misinterpreted as
// format strings to TfStringPrintf in Sdf_ComputeAnonLayerIdentifier.
// See discussion in https://github.com/PixarAnimationStudios/USD/pull/2022
idTag = TfStringReplace(idTag, "%", "%%");

return _Tokens->AnonLayerPrefix.GetString() + "%p" +
(idTag.empty() ? idTag : ":" + idTag);
}
Expand Down
5 changes: 5 additions & 0 deletions pxr/usd/usd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ pxr_install_test_dir(
DEST testUsdAppliedAPISchemas
)

pxr_install_test_dir(
SRC testenv/testUsdStage
DEST testUsdStage
)

pxr_install_test_dir(
SRC testenv/testUsdAppliedAPISchemas
DEST testUsdAppliedAPISchemas_AutoApplyDisabled
Expand Down
4 changes: 4 additions & 0 deletions pxr/usd/usd/testenv/testUsdStage.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
allFormats = ['usd' + c for c in 'ac']

class TestUsdStage(unittest.TestCase):
def test_URLEncodedIdentifiers(self):
stage = Usd.Stage.Open("Libeccio%20LowFBX.usda")
assert stage

def test_Repr(self):
stage = Usd.Stage.CreateInMemory()

Expand Down
17 changes: 17 additions & 0 deletions pxr/usd/usd/testenv/testUsdStage/Libeccio%20LowFBX.usda
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#usda 1.0
(
defaultPrim = "hello"
)

def Xform "hello"
{
custom double3 xformOp:translate = (4, 5, 6)
uniform token[] xformOpOrder = ["xformOp:translate"]

def Sphere "world"
{
float3[] extent = [(-2, -2, -2), (2, 2, 2)]
color3f[] primvars:displayColor = [(0, 0, 1)]
double radius = 2
}
}

0 comments on commit 5cd971b

Please sign in to comment.