Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BR] Fix integer overflow in physx::writeCompressedContact causing sim corruption #357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions physx/include/PxContact.h
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ struct PxContactPatch
/**
\brief The number of contacts in this patch
*/
PxU8 nbContacts;
PxU16 nbContacts;

/**
\brief The combined material flag of two actors that come in contact
@@ -129,7 +129,7 @@ struct PxContactPatch
*/
PxU16 materialIndex1;

PxU16 pad[5];
PxU16 pad[4];
}
PX_ALIGN_SUFFIX(16);

Original file line number Diff line number Diff line change
@@ -64,10 +64,10 @@ void combineMaterials(const PxsMaterialManager* materialManager, PxU16 origMatIn

struct StridePatch
{
PxU8 startIndex;
PxU8 endIndex;
PxU16 startIndex;
PxU16 endIndex;
PxU16 totalCount;
PxU8 nextIndex;
PxU8 totalCount;
bool isRoot;
};

@@ -116,13 +116,13 @@ PxU32 physx::writeCompressedContact(const PxContactPoint* const PX_RESTRICT cont
{
StridePatch& patch = stridePatches[numStrideHeaders-1];

patch.startIndex = PxU8(strideStart);
patch.endIndex = PxU8(a);
patch.startIndex = PxU16(strideStart);
patch.endIndex = PxU16(a);
patch.nextIndex = 0xFF;
patch.totalCount = PxU8(a - strideStart);
patch.totalCount = PxU16(a - strideStart);
patch.isRoot = root;
if(parentRootPatch)
parentRootPatch->totalCount += PxU8(a - strideStart);
parentRootPatch->totalCount += PxU16(a - strideStart);

root = true;
parentRootPatch = NULL;
@@ -163,15 +163,16 @@ PxU32 physx::writeCompressedContact(const PxContactPoint* const PX_RESTRICT cont
}
{
StridePatch& patch = stridePatches[numStrideHeaders-1];
patch.startIndex = PxU8(strideStart);
patch.endIndex = PxU8(numContactPoints);
patch.startIndex = PxU16(strideStart);
patch.endIndex = PxU16(numContactPoints);
patch.nextIndex = 0xFF;
patch.totalCount = PxU8(numContactPoints - strideStart);
patch.totalCount = PxU16(numContactPoints - strideStart);
patch.isRoot = root;
if(parentRootPatch)
parentRootPatch->totalCount += PxU8(numContactPoints - strideStart);
parentRootPatch->totalCount += PxU16(numContactPoints - strideStart);
}

PX_ASSERT(totalUniquePatches <= PX_MAX_U8);
numPatches = PxU8(totalUniquePatches);

//Calculate the number of patches/points required
Original file line number Diff line number Diff line change
@@ -242,9 +242,9 @@ class PxsCMDiscreteUpdateTask : public PxsCMUpdateTask
patches[k + 1].materialFlags = patches[k].materialFlags;
patches[k + 1].internalFlags = patches[k].internalFlags;
patches[k + 1].startContactIndex = PxTo8(j + startIndex);
patches[k + 1].nbContacts = PxTo8(patches[k].nbContacts - j);
patches[k + 1].nbContacts = PxTo16(patches[k].nbContacts - j);
//Fill in patch information now that final patches are available
patches[k].nbContacts = PxU8(j);
patches[k].nbContacts = PxU16(j);
break; // we're done with all contacts in patch k because the remaining were just transferrred to patch k+1
}
}