1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

Coding - Fix draco buffer index out of bounds

Fixed an exception where the bufferIndex is out of bounds.
Happens when Draco compression is combined with SetMergeFaces.
This commit is contained in:
Elias Cohenca 2025-01-23 02:25:08 +02:00 committed by GitHub
parent 87a64bbad5
commit bb84ecf5c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -746,6 +746,10 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
continue; continue;
} }
for (RWGltf_GltfFaceList::Iterator aGltfFaceIter (*aGltfFaceList); aGltfFaceIter.More() && aPSentryBin.More(); aGltfFaceIter.Next())
{
const Handle(RWGltf_GltfFace)& aGltfFace = aGltfFaceIter.Value();
std::shared_ptr<RWGltf_CafWriter::Mesh> aMeshPtr; std::shared_ptr<RWGltf_CafWriter::Mesh> aMeshPtr;
#ifdef HAVE_DRACO #ifdef HAVE_DRACO
++aMeshIndex; ++aMeshIndex;
@ -763,10 +767,6 @@ bool RWGltf_CafWriter::writeBinData (const Handle(TDocStd_Document)& theDocument
} }
#endif #endif
for (RWGltf_GltfFaceList::Iterator aGltfFaceIter (*aGltfFaceList); aGltfFaceIter.More() && aPSentryBin.More(); aGltfFaceIter.Next())
{
const Handle(RWGltf_GltfFace)& aGltfFace = aGltfFaceIter.Value();
Handle(RWGltf_GltfFace) anOldGltfFace; Handle(RWGltf_GltfFace) anOldGltfFace;
if (aWrittenPrimData.Find (aGltfFace->Shape, anOldGltfFace)) if (aWrittenPrimData.Find (aGltfFace->Shape, anOldGltfFace))
{ {
@ -1899,24 +1899,22 @@ void RWGltf_CafWriter::writeMeshes (const RWGltf_GltfSceneNodeMap& theSceneNodeM
for (RWGltf_GltfFaceList::Iterator aFaceGroupIter (*aGltfFaceList); aFaceGroupIter.More(); aFaceGroupIter.Next()) for (RWGltf_GltfFaceList::Iterator aFaceGroupIter (*aGltfFaceList); aFaceGroupIter.More(); aFaceGroupIter.Next())
{ {
const Handle(RWGltf_GltfFace)& aGltfFace = aFaceGroupIter.Value(); const Handle(RWGltf_GltfFace)& aGltfFace = aFaceGroupIter.Value();
const int aPrevSize = aDracoBufIndMap.Size(); int aCurrentDracoBufInd = 0;
const int aTempDracoBufInd = aDracoBufInd;
if (myDracoParameters.DracoCompression
&& !aDracoBufIndMap.FindFromKey (aGltfFace->NodePos.Id, aDracoBufInd))
{
aDracoBufIndMap.Add (aGltfFace->NodePos.Id, aDracoBufInd);
}
writePrimArray (*aGltfFace, aNodeName, aDracoBufInd, toStartPrims); if (myDracoParameters.DracoCompression)
if (aTempDracoBufInd != aDracoBufInd)
{ {
aDracoBufInd = aTempDracoBufInd; // Check if we've seen this NodePos.Id before
} if (!aDracoBufIndMap.FindFromKey(aGltfFace->NodePos.Id, aCurrentDracoBufInd))
if (!myDracoParameters.DracoCompression || aDracoBufIndMap.Size() > aPrevSize)
{ {
// New Draco buffer entry needed
aCurrentDracoBufInd = aDracoBufInd;
aDracoBufIndMap.Add(aGltfFace->NodePos.Id, aCurrentDracoBufInd);
++aDracoBufInd; ++aDracoBufInd;
} }
} }
writePrimArray(*aGltfFace, aNodeName, aCurrentDracoBufInd, toStartPrims);
}
} }
else else
{ {
@ -1935,24 +1933,22 @@ void RWGltf_CafWriter::writeMeshes (const RWGltf_GltfSceneNodeMap& theSceneNodeM
} }
const Handle(RWGltf_GltfFace)& aGltfFace = aGltfFaceList->First(); const Handle(RWGltf_GltfFace)& aGltfFace = aGltfFaceList->First();
const int aPrevSize = aDracoBufIndMap.Size(); int aCurrentDracoBufInd = 0;
const int aTempDracoBufInd = aDracoBufInd;
if (myDracoParameters.DracoCompression
&& !aDracoBufIndMap.FindFromKey(aGltfFace->NodePos.Id, aDracoBufInd))
{
aDracoBufIndMap.Add(aGltfFace->NodePos.Id, aDracoBufInd);
}
writePrimArray (*aGltfFace, aNodeName, aDracoBufInd, toStartPrims); if (myDracoParameters.DracoCompression)
if (aTempDracoBufInd != aDracoBufInd)
{ {
aDracoBufInd = aTempDracoBufInd; // Check if we've seen this NodePos.Id before
} if (!aDracoBufIndMap.FindFromKey(aGltfFace->NodePos.Id, aCurrentDracoBufInd))
if (!myDracoParameters.DracoCompression || aDracoBufIndMap.Size() > aPrevSize)
{ {
// New Draco buffer entry needed
aCurrentDracoBufInd = aDracoBufInd;
aDracoBufIndMap.Add(aGltfFace->NodePos.Id, aCurrentDracoBufInd);
++aDracoBufInd; ++aDracoBufInd;
} }
} }
writePrimArray(*aGltfFace, aNodeName, aCurrentDracoBufInd, toStartPrims);
}
} }
if (!toStartPrims) if (!toStartPrims)