Skip to content

Commit 6613cfc

Browse files
authored
Added extra bounds checks (#288)
Resolves MSRC 113268 which is a low risk information disclosure bug.
1 parent 24b64e0 commit 6613cfc

6 files changed

Lines changed: 30 additions & 8 deletions

DirectXMesh/DirectXMeshAdjacency.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,11 @@ namespace
374374
const uint32_t v2 = pointRep[i1];
375375
const uint32_t v3 = pointRep[i2];
376376

377+
if (v1 >= nVerts
378+
|| v2 >= nVerts
379+
|| v3 >= nVerts)
380+
return E_UNEXPECTED;
381+
377382
// filter out degenerate triangles
378383
if (v1 == v2 || v1 == v3 || v2 == v3)
379384
continue;

DirectXMesh/DirectXMeshGSAdjacency.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ namespace
6464
{
6565
indicesAdj[outputi] = indices[face * 3 + ((point + 2) % 3)];
6666
}
67+
else if (a >= nFaces)
68+
{
69+
return E_UNEXPECTED;
70+
}
6771
else
6872
{
6973
uint32_t v1 = indices[face * 3 + point];
@@ -82,6 +86,10 @@ namespace
8286
v1 = pointRep[v1];
8387
v2 = pointRep[v2];
8488

89+
if (((v1 != UNUSED32) && (v1 >= nVerts))
90+
|| ((v2 != UNUSED32) && (v2 >= nVerts)))
91+
return E_UNEXPECTED;
92+
8593
uint32_t vOther = UNUSED32;
8694

8795
// find other vertex

DirectXMesh/DirectXMeshOptimizeTVC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ namespace
112112

113113
if (neighbor != UNUSED32)
114114
{
115+
if (neighbor >= nFaces)
116+
return E_UNEXPECTED;
117+
115118
if ((neighbor < faceOffset) || (neighbor >= faceMax)
116119
|| (neighbor == adjacency[face * 3 + ((n + 1) % 3)])
117120
|| (neighbor == adjacency[face * 3 + ((n + 2) % 3)]))

DirectXMesh/DirectXMeshRemap.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace
6666
}
6767
}
6868
else
69-
return E_FAIL;
69+
return E_UNEXPECTED;
7070
}
7171

7272
return S_OK;
@@ -667,7 +667,7 @@ HRESULT DirectX::FinalizeVB(
667667
}
668668
else if (src >= newVerts)
669669
{
670-
return E_FAIL;
670+
return E_UNEXPECTED;
671671
}
672672
else if (src < nVerts)
673673
{
@@ -768,7 +768,7 @@ HRESULT DirectX::FinalizeVBAndPointReps(
768768
if (vertexRemap[j] != UNUSED32)
769769
{
770770
if (vertexRemap[j] >= newVerts)
771-
return E_INVALIDARG;
771+
return E_UNEXPECTED;
772772

773773
vertexRemapInverse[vertexRemap[j]] = j;
774774
}
@@ -790,7 +790,11 @@ HRESULT DirectX::FinalizeVBAndPointReps(
790790

791791
for (size_t i = 0; i < nDupVerts; ++i)
792792
{
793-
pointRep[i + nVerts] = prin[dupVerts[i]];
793+
uint32_t pr = dupVerts[i];
794+
if (pr >= nDupVerts)
795+
return E_UNEXPECTED;
796+
797+
pointRep[i + nVerts] = prin[pr];
794798
}
795799

796800
for (size_t j = 0; j < newVerts; ++j)
@@ -801,10 +805,6 @@ HRESULT DirectX::FinalizeVBAndPointReps(
801805
{
802806
// remap entry is unused
803807
}
804-
else if (src >= newVerts)
805-
{
806-
return E_FAIL;
807-
}
808808
else if (src < nVerts)
809809
{
810810
memcpy(dptr, sptr + src * stride, stride);

DirectXMesh/DirectXMeshUtil.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ namespace
478478
if (indices[j] == index_t(-1))
479479
continue;
480480

481+
if (indices[j] >= nVerts)
482+
return;
483+
481484
bool found = false;
482485

483486
for (size_t ptr = 0; ptr < cacheSize; ++ptr)

DirectXMesh/DirectXMeshWeldVertices.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ namespace
120120
if (i == index_t(-1))
121121
continue;
122122

123+
if (i >= nVerts)
124+
return E_UNEXPECTED;
125+
123126
indices[j] = index_t(vertexRemapInverse[i]);
124127
}
125128

0 commit comments

Comments
 (0)