From ffeee9bfdeba868c53badee8285d37576dca9ade Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Fri, 2 Apr 2021 15:42:35 -0400 Subject: [PATCH] Fix lost precision case in SkComputeRadialSteps. With large offsets, we can end up with a tiny change in angle at each radial step, so that rotSin and rotCos can get truncated to 0 and/or 1, respectively. This means that we won't sweep the entire radial distance, throwing future calculations off. Instead in this case we should fail. Bug: oss-fuzz:21826 Change-Id: I24f5b1ac315a3697d2ea00ee4bd73652ec3e16dd Reviewed-on: https://skia-review.googlesource.com/c/skia/+/392377 Commit-Queue: Jim Van Verth Reviewed-by: Kevin Lubick --- src/utils/SkPolyUtils.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp index 00dc5a43dc..fbf6038cab 100644 --- a/src/utils/SkPolyUtils.cpp +++ b/src/utils/SkPolyUtils.cpp @@ -494,6 +494,11 @@ bool SkComputeRadialSteps(const SkVector& v1, const SkVector& v2, SkScalar offse SkScalar dTheta = steps > 0 ? theta / steps : 0; *rotSin = SkScalarSin(dTheta); *rotCos = SkScalarCos(dTheta); + // Our offset may be so large that we end up with a tiny dTheta, in which case we + // lose precision when computing rotSin and rotCos. + if (steps > 0 && (*rotSin == 0 || *rotCos == 1)) { + return false; + } *n = steps; return true; }