Skip to content

Commit

Permalink
Fix off-by-one illegal read in MergeConvexHulls (#51)
Browse files Browse the repository at this point in the history
Fixing an illegal off-by-one read of the costMatrix during the swap of the last column of the costMatrix into its new location.

We only need to update the column values from after p1 to the new last column at index costSize - 1 (costSize being already updated to the new reduced size here!).

Hence the looping: for (i = p1+1; i < costSize)
  • Loading branch information
ChuangTseu authored Jul 20, 2024
1 parent b3d808f commit 8e06bfb
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,11 @@ namespace coacd

++top_row;
rowIdx += p1;
for (size_t i = p1 + 1; i < (costSize + 1); ++i)
for (size_t i = p1 + 1; i < costSize; ++i)
{
costMatrix[rowIdx] = costMatrix[top_row];
precostMatrix[rowIdx] = precostMatrix[top_row++];
rowIdx += i;
assert(rowIdx >= 0);
}
}
costMatrix.resize(erase_idx);
Expand Down

0 comments on commit 8e06bfb

Please sign in to comment.