| Mike Klein | b18eb35 | 2018-03-22 11:32:09 -0400 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2018 Google Inc. | 
 | 3 |  * | 
 | 4 |  * Use of this source code is governed by a BSD-style license that can be | 
 | 5 |  * found in the LICENSE file. | 
 | 6 |  */ | 
 | 7 |  | 
| Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" | 
| Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkPaint.h" | 
 | 10 | #include "include/core/SkPath.h" | 
| Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkPathEffect.h" | 
 | 12 | #include "include/core/SkTypes.h" | 
| Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "include/effects/SkDashPathEffect.h" | 
| Mike Klein | b18eb35 | 2018-03-22 11:32:09 -0400 | [diff] [blame] | 14 |  | 
 | 15 | // Repro case for skia:7674.  Requires lots of RAM to run, and currently triggers UB: | 
 | 16 | // ../include/private/SkTDArray.h:382:26: | 
 | 17 | //   runtime error: signed integer overflow: 2147483644 + 4 cannot be represented in type 'int' | 
 | 18 |  | 
| Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 19 | static SK_UNUSED void path_measure_explosion(SkCanvas* canvas) { | 
| Mike Klein | b18eb35 | 2018-03-22 11:32:09 -0400 | [diff] [blame] | 20 |     SkPaint p; | 
 | 21 |     p.setAntiAlias(false); | 
 | 22 |     float intervals[] = { 0, 10e9f }; | 
 | 23 |     p.setStyle(SkPaint::kStroke_Style); | 
 | 24 |     p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); | 
 | 25 |  | 
 | 26 |     int quadratic_at[] = { | 
 | 27 |         13, 68, 258, 1053, 1323, 2608, 10018, 15668, 59838, 557493, 696873, 871098, 4153813, | 
 | 28 |         15845608, 48357008, 118059138, 288230353, 360287948, 562949933, 703687423, 1099511613, 0 | 
 | 29 |     }; | 
 | 30 |     int next_quadratic_at = 0; | 
 | 31 |  | 
 | 32 |     SkPath path; | 
 | 33 |     path.moveTo(0, 0); | 
 | 34 |  | 
 | 35 |     int i = 1; | 
 | 36 |     for (int points = 1; points < 2147483647; ) { | 
 | 37 |         if (points == quadratic_at[next_quadratic_at]) { | 
 | 38 |             path.quadTo(i, 0, i, 0); | 
 | 39 |             next_quadratic_at++; | 
 | 40 |             points += 2; | 
 | 41 |         } else { | 
 | 42 |             path.lineTo(i, 0); | 
 | 43 |             points += 1; | 
 | 44 |         } | 
 | 45 |  | 
 | 46 |         i++; | 
 | 47 |  | 
 | 48 |         if (i == 1000000) { | 
 | 49 |             path.moveTo(0, 0); | 
 | 50 |             points += 1; | 
 | 51 |             i = 1; | 
 | 52 |         } | 
 | 53 |     } | 
 | 54 |     canvas->drawPath(path, p); | 
 | 55 | } | 
| Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 56 |  | 
 | 57 | #if 0 | 
 | 58 | #include "gm/gm.h" | 
 | 59 | DEF_SIMPLE_GM(PathMeasure_explosion, canvas, 500,500) { | 
 | 60 |     path_measure_explosion(canvas); | 
 | 61 | } | 
| Mike Klein | b18eb35 | 2018-03-22 11:32:09 -0400 | [diff] [blame] | 62 | #endif |