Merge pull request #2656 from ShabbyX/fix-oob

Fix OOB write in matrix constructor
This commit is contained in:
Greg Fischer 2021-06-04 11:00:27 -06:00 committed by GitHub
commit 2675cc3f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2543,7 +2543,7 @@ Id Builder::createMatrixConstructor(Decoration precision, const std::vector<Id>&
int row = 0; int row = 0;
int col = 0; int col = 0;
for (int arg = 0; arg < (int)sources.size(); ++arg) { for (int arg = 0; arg < (int)sources.size() && col < numCols; ++arg) {
Id argComp = sources[arg]; Id argComp = sources[arg];
for (int comp = 0; comp < getNumComponents(sources[arg]); ++comp) { for (int comp = 0; comp < getNumComponents(sources[arg]); ++comp) {
if (getNumComponents(sources[arg]) > 1) { if (getNumComponents(sources[arg]) > 1) {
@ -2555,6 +2555,10 @@ Id Builder::createMatrixConstructor(Decoration precision, const std::vector<Id>&
row = 0; row = 0;
col++; col++;
} }
if (col == numCols) {
// If more components are provided than fit the matrix, discard the rest.
break;
}
} }
} }
} }