Skip to content

Commit 4c83fdb

Browse files
committed
Fix out of boundary vector access
Fixes #3028 Fixes #3029
1 parent e1c16e0 commit 4c83fdb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/permutate.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Sass {
2424

2525
size_t L = in.size(), n = 0;
2626

27+
if (L == 0) return {};
2728
// Exit early if any entry is empty
2829
for (size_t i = 0; i < L; i += 1) {
2930
if (in[i].size() == 0) return {};
@@ -80,12 +81,18 @@ namespace Sass {
8081

8182
size_t L = in.size();
8283
size_t n = in.size() - 1;
84+
85+
if (L == 0) return {};
86+
// Exit early if any entry is empty
87+
for (size_t i = 0; i < L; i += 1) {
88+
if (in[i].size() == 0) return {};
89+
}
90+
8391
size_t* state = new size_t[L];
8492
std::vector< std::vector<T>> out;
8593

8694
// First initialize all states for every permutation group
8795
for (size_t i = 0; i < L; i += 1) {
88-
if (in[i].size() == 0) return {};
8996
state[i] = in[i].size() - 1;
9097
}
9198

@@ -104,10 +111,8 @@ namespace Sass {
104111
// Current group finished
105112
if (state[n] == 0) {
106113
// Find position of next decrement
107-
while (n > 0 && state[--n] == 0)
108-
{
114+
while (n > 0 && state[--n] == 0) {}
109115

110-
}
111116
// Check for end condition
112117
if (state[n] != 0) {
113118
// Decrease next on the left side

0 commit comments

Comments
 (0)