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

Unified Diff: xfa/fde/xml/fde_xml_imp.cpp

Issue 2223823003: Guard against undefined shift. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Update windows result Created 4 years, 4 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 | xfa/fde/xml/fde_xml_imp_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: xfa/fde/xml/fde_xml_imp.cpp
diff --git a/xfa/fde/xml/fde_xml_imp.cpp b/xfa/fde/xml/fde_xml_imp.cpp
index 4c6dcf989c4c910835c41ac17ea0adb58962ad9a..60afa89038713744f953bdc4a85226e70e41fc2b 100644
--- a/xfa/fde/xml/fde_xml_imp.cpp
+++ b/xfa/fde/xml/fde_xml_imp.cpp
@@ -1857,25 +1857,36 @@ void CFDE_XMLSyntaxParser::ParseTextChar(FX_WCHAR ch) {
ch = 0;
FX_WCHAR w;
if (iLen > 1 && csEntity[1] == L'x') {
- for (int32_t i = 2; i < iLen; i++) {
- w = csEntity[i];
- if (w >= L'0' && w <= L'9') {
- ch = (ch << 4) + w - L'0';
- } else if (w >= L'A' && w <= L'F') {
- ch = (ch << 4) + w - 55;
- } else if (w >= L'a' && w <= L'f') {
- ch = (ch << 4) + w - 87;
- } else {
- break;
+ int32_t i = 2;
+ while (i < iLen && csEntity[i] == '0')
+ i++;
+ if (iLen - i <= 4) {
+ for (; i < iLen; i++) {
+ w = csEntity[i];
+ if (w >= L'0' && w <= L'9') {
+ ch = (ch << 4) + w - L'0';
+ } else if (w >= L'A' && w <= L'F') {
+ ch = (ch << 4) + w - 55;
+ } else if (w >= L'a' && w <= L'f') {
+ ch = (ch << 4) + w - 87;
+ } else {
+ break;
+ }
}
+ } else {
+ ch = ' ';
}
} else {
for (int32_t i = 1; i < iLen; i++) {
w = csEntity[i];
- if (w < L'0' || w > L'9') {
+ if (w < L'0' || w > L'9')
break;
- }
ch = ch * 10 + w - L'0';
+
+ if (ch < 0) {
Wei Li 2016/08/10 17:28:30 Could you also use length based checking here? If
dsinclair 2016/08/10 17:31:04 I don't think so. This check doesn't do the shifts
Wei Li 2016/08/10 20:18:48 Sorry for the back and forth. I am trying to find
dsinclair 2016/08/10 20:58:08 No need to apologize, code working same on all pla
+ ch = ' ';
+ break;
+ }
}
}
if (ch != 0) {
« no previous file with comments | « no previous file | xfa/fde/xml/fde_xml_imp_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698