From 4b95360b7611aa73f928de2dc47390f78573c6cc Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Wed, 21 Jun 2017 17:01:02 -0400 Subject: Clamp instead of checked_cast in TT2PDF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: chromium:727938 Change-Id: I85fe329c9d19c1dd1303279b0a9aade2fcc3211c Reviewed-on: https://pdfium-review.googlesource.com/6814 Commit-Queue: Nicolás Peña Reviewed-by: dsinclair --- core/fpdfapi/font/cpdf_font.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index bdd3464ed2..82f9be3361 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp @@ -6,6 +6,7 @@ #include "core/fpdfapi/font/cpdf_font.h" +#include #include #include #include @@ -486,8 +487,11 @@ int CPDF_Font::TT2PDF(int m, FXFT_Face face) { int upm = FXFT_Get_Face_UnitsPerEM(face); if (upm == 0) return m; - return pdfium::base::checked_cast( - (static_cast(m) * 1000 + upm / 2) / upm); + + return static_cast( + pdfium::clamp((m * 1000.0 + upm / 2) / upm, + static_cast(std::numeric_limits::min()), + static_cast(std::numeric_limits::max()))); } // static -- cgit v1.2.3