OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDashPathEffect.h" | 8 #include "SkDashPathEffect.h" |
9 | 9 |
10 #include "SkDashPathPriv.h" | 10 #include "SkDashPathPriv.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 len2 -= clampedInitialDashLength; | 241 len2 -= clampedInitialDashLength; |
242 } | 242 } |
243 len2 -= fIntervals[1]; // also skip first space | 243 len2 -= fIntervals[1]; // also skip first space |
244 if (len2 < 0) { | 244 if (len2 < 0) { |
245 len2 = 0; | 245 len2 = 0; |
246 } | 246 } |
247 } else { | 247 } else { |
248 len2 -= clampedInitialDashLength; // skip initial partial empty | 248 len2 -= clampedInitialDashLength; // skip initial partial empty |
249 } | 249 } |
250 } | 250 } |
251 int numMidPoints = SkScalarFloorToInt(len2 / fIntervalLength); | 251 // Too many midpoints can cause results->fNumPoints to overflow or |
reed1
2016/07/20 18:06:15
Alternative: we could just return false if the val
| |
252 // otherwise cause the results->fPoints allocation below to OOM. | |
253 // Cap it to a sane value. | |
254 static const SkScalar kMaxPoints = 1000000; | |
255 SkScalar numIntervals = len2 / fIntervalLength; | |
256 if (!SkScalarIsFinite(numIntervals) || numIntervals > kMaxPoints) { | |
257 return false; | |
258 } | |
259 int numMidPoints = SkScalarFloorToInt(numIntervals); | |
252 results->fNumPoints += numMidPoints; | 260 results->fNumPoints += numMidPoints; |
253 len2 -= numMidPoints * fIntervalLength; | 261 len2 -= numMidPoints * fIntervalLength; |
254 bool partialLast = false; | 262 bool partialLast = false; |
255 if (len2 > 0) { | 263 if (len2 > 0) { |
256 if (len2 < fIntervals[0]) { | 264 if (len2 < fIntervals[0]) { |
257 partialLast = true; | 265 partialLast = true; |
258 } else { | 266 } else { |
259 ++numMidPoints; | 267 ++numMidPoints; |
260 ++results->fNumPoints; | 268 ++results->fNumPoints; |
261 } | 269 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 #endif | 393 #endif |
386 | 394 |
387 //////////////////////////////////////////////////////////////////////////////// ////////////////// | 395 //////////////////////////////////////////////////////////////////////////////// ////////////////// |
388 | 396 |
389 sk_sp<SkPathEffect> SkDashPathEffect::Make(const SkScalar intervals[], int count , SkScalar phase) { | 397 sk_sp<SkPathEffect> SkDashPathEffect::Make(const SkScalar intervals[], int count , SkScalar phase) { |
390 if (!SkDashPath::ValidDashPath(phase, intervals, count)) { | 398 if (!SkDashPath::ValidDashPath(phase, intervals, count)) { |
391 return nullptr; | 399 return nullptr; |
392 } | 400 } |
393 return sk_sp<SkPathEffect>(new SkDashPathEffect(intervals, count, phase)); | 401 return sk_sp<SkPathEffect>(new SkDashPathEffect(intervals, count, phase)); |
394 } | 402 } |
OLD | NEW |