Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2046)

Unified Diff: core/fpdfapi/fpdf_font/fpdf_font_cid.cpp

Issue 2358023002: Check for overflow in CMap_GetCode. (Closed)
Patch Set: Review fixes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_font/fpdf_font_cid.cpp
diff --git a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp
index 3f95ec4a96cb12172f801ce4e424fa26b1b45425..96c1ef57533cbda68437ad9fce441136daa5a75f 100644
--- a/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp
+++ b/core/fpdfapi/fpdf_font/fpdf_font_cid.cpp
@@ -441,16 +441,22 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
// Static.
uint32_t CPDF_CMapParser::CMap_GetCode(const CFX_ByteStringC& word) {
- int num = 0;
+ pdfium::base::CheckedNumeric<uint32_t> num = 0;
if (word.GetAt(0) == '<') {
- for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i)
+ for (int i = 1; i < word.GetLength() && std::isxdigit(word.GetAt(i)); ++i) {
num = num * 16 + FXSYS_toHexDigit(word.GetAt(i));
- return num;
+ if (!num.IsValid())
+ return 0;
+ }
+ return num.ValueOrDie();
}
- for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i)
+ for (int i = 0; i < word.GetLength() && std::isdigit(word.GetAt(i)); ++i) {
num = num * 10 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(word.GetAt(i)));
- return num;
+ if (!num.IsValid())
+ return 0;
+ }
+ return num.ValueOrDie();
}
// Static.
« no previous file with comments | « no previous file | core/fpdfapi/fpdf_font/fpdf_font_cid_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698