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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp

Issue 1433513002: Revert "Revert "Revert "Revert "Cleanup some numeric code."""" (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "../../../../third_party/base/nonstd_unique_ptr.h" 11 #include "../../../../third_party/base/nonstd_unique_ptr.h"
12 #include "../../../../third_party/base/stl_util.h" 12 #include "../../../../third_party/base/stl_util.h"
13 #include "../../../include/fpdfapi/fpdf_module.h" 13 #include "../../../include/fpdfapi/fpdf_module.h"
14 #include "../../../include/fpdfapi/fpdf_page.h" 14 #include "../../../include/fpdfapi/fpdf_page.h"
15 #include "../../../include/fpdfapi/fpdf_parser.h" 15 #include "../../../include/fpdfapi/fpdf_parser.h"
16 #include "../../../include/fxcrt/fx_ext.h"
16 #include "../../../include/fxcrt/fx_safe_types.h" 17 #include "../../../include/fxcrt/fx_safe_types.h"
17 #include "../fpdf_page/pageint.h" 18 #include "../fpdf_page/pageint.h"
18 #include "parser_int.h" 19 #include "parser_int.h"
19 20
20 namespace { 21 namespace {
21 22
22 struct SearchTagRecord { 23 struct SearchTagRecord {
23 const uint8_t* m_pTag; 24 const uint8_t* m_pTag;
24 FX_DWORD m_Len; 25 FX_DWORD m_Len;
25 FX_DWORD m_Offset; 26 FX_DWORD m_Offset;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 157 }
157 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); 158 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler();
158 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); 159 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*);
159 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, 160 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
160 FX_BOOL bReParse, 161 FX_BOOL bReParse,
161 FX_BOOL bOwnFileRead) { 162 FX_BOOL bOwnFileRead) {
162 CloseParser(bReParse); 163 CloseParser(bReParse);
163 m_bXRefStream = FALSE; 164 m_bXRefStream = FALSE;
164 m_LastXRefOffset = 0; 165 m_LastXRefOffset = 0;
165 m_bOwnFileRead = bOwnFileRead; 166 m_bOwnFileRead = bOwnFileRead;
167
166 int32_t offset = GetHeaderOffset(pFileAccess); 168 int32_t offset = GetHeaderOffset(pFileAccess);
167 if (offset == -1) { 169 if (offset == -1) {
168 if (bOwnFileRead && pFileAccess) { 170 if (bOwnFileRead && pFileAccess)
169 pFileAccess->Release(); 171 pFileAccess->Release();
170 }
171 return PDFPARSE_ERROR_FORMAT; 172 return PDFPARSE_ERROR_FORMAT;
172 } 173 }
173 m_Syntax.InitParser(pFileAccess, offset); 174 m_Syntax.InitParser(pFileAccess, offset);
175
174 uint8_t ch; 176 uint8_t ch;
175 if (!m_Syntax.GetCharAt(5, ch)) { 177 if (!m_Syntax.GetCharAt(5, ch))
176 return PDFPARSE_ERROR_FORMAT; 178 return PDFPARSE_ERROR_FORMAT;
177 } 179 if (std::isdigit(ch))
178 if (ch >= '0' && ch <= '9') { 180 m_FileVersion = FXSYS_toDecimalDigit(ch) * 10;
179 m_FileVersion = (ch - '0') * 10; 181
180 } 182 if (!m_Syntax.GetCharAt(7, ch))
181 if (!m_Syntax.GetCharAt(7, ch)) {
182 return PDFPARSE_ERROR_FORMAT; 183 return PDFPARSE_ERROR_FORMAT;
183 } 184 if (std::isdigit(ch))
184 if (ch >= '0' && ch <= '9') { 185 m_FileVersion += FXSYS_toDecimalDigit(ch);
185 m_FileVersion += ch - '0'; 186
186 } 187 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9)
187 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) {
188 return PDFPARSE_ERROR_FORMAT; 188 return PDFPARSE_ERROR_FORMAT;
189 } 189
190 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); 190 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9);
191 if (!bReParse) { 191 if (!bReParse)
192 m_pDocument = new CPDF_Document(this); 192 m_pDocument = new CPDF_Document(this);
193 } 193
194 FX_BOOL bXRefRebuilt = FALSE; 194 FX_BOOL bXRefRebuilt = FALSE;
195 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) { 195 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) {
196 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); 196 FX_FILESIZE startxref_offset = m_Syntax.SavePos();
197 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), 197 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(),
198 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), 198 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE),
199 CompareFileSize); 199 CompareFileSize);
200 if (pResult == NULL) { 200 if (!pResult)
201 m_SortedOffset.Add(startxref_offset); 201 m_SortedOffset.Add(startxref_offset);
202 } 202
203 m_Syntax.GetKeyword(); 203 m_Syntax.GetKeyword();
204 FX_BOOL bNumber; 204 FX_BOOL bNumber;
205 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); 205 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber);
206 if (!bNumber) { 206 if (!bNumber)
207 return PDFPARSE_ERROR_FORMAT; 207 return PDFPARSE_ERROR_FORMAT;
208 } 208
209 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); 209 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str);
210 if (!LoadAllCrossRefV4(m_LastXRefOffset) && 210 if (!LoadAllCrossRefV4(m_LastXRefOffset) &&
211 !LoadAllCrossRefV5(m_LastXRefOffset)) { 211 !LoadAllCrossRefV5(m_LastXRefOffset)) {
212 if (!RebuildCrossRef()) { 212 if (!RebuildCrossRef())
213 return PDFPARSE_ERROR_FORMAT; 213 return PDFPARSE_ERROR_FORMAT;
214 } 214
215 bXRefRebuilt = TRUE; 215 bXRefRebuilt = TRUE;
216 m_LastXRefOffset = 0; 216 m_LastXRefOffset = 0;
217 } 217 }
218 } else { 218 } else {
219 if (!RebuildCrossRef()) { 219 if (!RebuildCrossRef())
220 return PDFPARSE_ERROR_FORMAT; 220 return PDFPARSE_ERROR_FORMAT;
221 } 221
222 bXRefRebuilt = TRUE; 222 bXRefRebuilt = TRUE;
223 } 223 }
224 FX_DWORD dwRet = SetEncryptHandler(); 224 FX_DWORD dwRet = SetEncryptHandler();
225 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 225 if (dwRet != PDFPARSE_ERROR_SUCCESS)
226 return dwRet; 226 return dwRet;
227 } 227
228 m_pDocument->LoadDoc(); 228 m_pDocument->LoadDoc();
229 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { 229 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) {
230 if (bXRefRebuilt) { 230 if (bXRefRebuilt)
231 return PDFPARSE_ERROR_FORMAT; 231 return PDFPARSE_ERROR_FORMAT;
232 } 232
233 ReleaseEncryptHandler(); 233 ReleaseEncryptHandler();
234 if (!RebuildCrossRef()) { 234 if (!RebuildCrossRef())
235 return PDFPARSE_ERROR_FORMAT; 235 return PDFPARSE_ERROR_FORMAT;
236 } 236
237 dwRet = SetEncryptHandler(); 237 dwRet = SetEncryptHandler();
238 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 238 if (dwRet != PDFPARSE_ERROR_SUCCESS)
239 return dwRet; 239 return dwRet;
240 } 240
241 m_pDocument->LoadDoc(); 241 m_pDocument->LoadDoc();
242 if (m_pDocument->GetRoot() == NULL) { 242 if (!m_pDocument->GetRoot())
243 return PDFPARSE_ERROR_FORMAT; 243 return PDFPARSE_ERROR_FORMAT;
244 }
245 } 244 }
246 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 245 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
247 sizeof(FX_FILESIZE), CompareFileSize); 246 sizeof(FX_FILESIZE), CompareFileSize);
248 FX_DWORD RootObjNum = GetRootObjNum(); 247 FX_DWORD RootObjNum = GetRootObjNum();
249 if (RootObjNum == 0) { 248 if (RootObjNum == 0) {
250 ReleaseEncryptHandler(); 249 ReleaseEncryptHandler();
251 RebuildCrossRef(); 250 RebuildCrossRef();
252 RootObjNum = GetRootObjNum(); 251 RootObjNum = GetRootObjNum();
253 if (RootObjNum == 0) { 252 if (RootObjNum == 0)
254 return PDFPARSE_ERROR_FORMAT; 253 return PDFPARSE_ERROR_FORMAT;
255 } 254
256 dwRet = SetEncryptHandler(); 255 dwRet = SetEncryptHandler();
257 if (dwRet != PDFPARSE_ERROR_SUCCESS) { 256 if (dwRet != PDFPARSE_ERROR_SUCCESS)
258 return dwRet; 257 return dwRet;
259 }
260 } 258 }
261 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
262 CPDF_Reference* pMetadata = 260 CPDF_Reference* pMetadata =
263 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); 261 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")));
264 if (pMetadata) 262 if (pMetadata)
265 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
266 } 264 }
267 return PDFPARSE_ERROR_SUCCESS; 265 return PDFPARSE_ERROR_SUCCESS;
268 } 266 }
269 FX_DWORD CPDF_Parser::SetEncryptHandler() { 267 FX_DWORD CPDF_Parser::SetEncryptHandler() {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 for (int32_t i = 0; i < block_size; i++) { 451 for (int32_t i = 0; i < block_size; i++) {
454 FX_DWORD objnum = start_objnum + block * 1024 + i; 452 FX_DWORD objnum = start_objnum + block * 1024 + i;
455 char* pEntry = pBuf + i * recordsize; 453 char* pEntry = pBuf + i * recordsize;
456 if (pEntry[17] == 'f') { 454 if (pEntry[17] == 'f') {
457 m_CrossRef.SetAtGrow(objnum, 0); 455 m_CrossRef.SetAtGrow(objnum, 0);
458 m_V5Type.SetAtGrow(objnum, 0); 456 m_V5Type.SetAtGrow(objnum, 0);
459 } else { 457 } else {
460 int32_t offset = FXSYS_atoi(pEntry); 458 int32_t offset = FXSYS_atoi(pEntry);
461 if (offset == 0) { 459 if (offset == 0) {
462 for (int32_t c = 0; c < 10; c++) { 460 for (int32_t c = 0; c < 10; c++) {
463 if (pEntry[c] < '0' || pEntry[c] > '9') { 461 if (!std::isdigit(pEntry[c]))
464 return FALSE; 462 return FALSE;
465 }
466 } 463 }
467 } 464 }
468 m_CrossRef.SetAtGrow(objnum, offset); 465 m_CrossRef.SetAtGrow(objnum, offset);
469 int32_t version = FXSYS_atoi(pEntry + 11); 466 int32_t version = FXSYS_atoi(pEntry + 11);
470 if (version >= 1) { 467 if (version >= 1) {
471 m_bVersionUpdated = TRUE; 468 m_bVersionUpdated = TRUE;
472 } 469 }
473 m_ObjVersion.SetAtGrow(objnum, version); 470 m_ObjVersion.SetAtGrow(objnum, version);
474 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { 471 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) {
475 void* pResult = FXSYS_bsearch( 472 void* pResult = FXSYS_bsearch(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 start_objnum--; 551 start_objnum--;
555 objnum = 0; 552 objnum = 0;
556 } 553 }
557 } 554 }
558 m_CrossRef.SetAtGrow(objnum, 0); 555 m_CrossRef.SetAtGrow(objnum, 0);
559 m_V5Type.SetAtGrow(objnum, 0); 556 m_V5Type.SetAtGrow(objnum, 0);
560 } else { 557 } else {
561 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); 558 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry);
562 if (offset == 0) { 559 if (offset == 0) {
563 for (int32_t c = 0; c < 10; c++) { 560 for (int32_t c = 0; c < 10; c++) {
564 if (pEntry[c] < '0' || pEntry[c] > '9') { 561 if (!std::isdigit(pEntry[c]))
565 return false; 562 return false;
566 }
567 } 563 }
568 } 564 }
569 m_CrossRef.SetAtGrow(objnum, offset); 565 m_CrossRef.SetAtGrow(objnum, offset);
570 int32_t version = FXSYS_atoi(pEntry + 11); 566 int32_t version = FXSYS_atoi(pEntry + 11);
571 if (version >= 1) { 567 if (version >= 1) {
572 m_bVersionUpdated = TRUE; 568 m_bVersionUpdated = TRUE;
573 } 569 }
574 m_ObjVersion.SetAtGrow(objnum, version); 570 m_ObjVersion.SetAtGrow(objnum, version);
575 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && 571 if (m_CrossRef[objnum] < m_Syntax.m_FileLen &&
576 !FindPosInOffsets(m_CrossRef[objnum])) { 572 !FindPosInOffsets(m_CrossRef[objnum])) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 if (size > 4096) { 620 if (size > 4096) {
625 size = 4096; 621 size = 4096;
626 } 622 }
627 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { 623 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) {
628 break; 624 break;
629 } 625 }
630 for (FX_DWORD i = 0; i < size; i++) { 626 for (FX_DWORD i = 0; i < size; i++) {
631 uint8_t byte = buffer[i]; 627 uint8_t byte = buffer[i];
632 switch (status) { 628 switch (status) {
633 case 0: 629 case 0:
634 if (PDFCharIsWhitespace(byte)) { 630 if (PDFCharIsWhitespace(byte))
635 status = 1; 631 status = 1;
636 } 632
637 if (byte <= '9' && byte >= '0') { 633 if (std::isdigit(byte)) {
638 --i; 634 --i;
639 status = 1; 635 status = 1;
640 } 636 }
637
641 if (byte == '%') { 638 if (byte == '%') {
642 inside_index = 0; 639 inside_index = 0;
643 status = 9; 640 status = 9;
644 } 641 }
642
645 if (byte == '(') { 643 if (byte == '(') {
646 status = 10; 644 status = 10;
647 depth = 1; 645 depth = 1;
648 } 646 }
647
649 if (byte == '<') { 648 if (byte == '<') {
650 inside_index = 1; 649 inside_index = 1;
651 status = 11; 650 status = 11;
652 } 651 }
653 if (byte == '\\') { 652
653 if (byte == '\\')
654 status = 13; 654 status = 13;
655 } 655
656 if (byte == 't') { 656 if (byte == 't') {
657 status = 7; 657 status = 7;
658 inside_index = 1; 658 inside_index = 1;
659 } 659 }
660 break; 660 break;
661 case 1: 661 case 1:
662 if (PDFCharIsWhitespace(byte)) { 662 if (PDFCharIsWhitespace(byte)) {
663 break; 663 break;
664 } else if (byte <= '9' && byte >= '0') { 664 } else if (std::isdigit(byte)) {
665 start_pos = pos + i; 665 start_pos = pos + i;
666 status = 2; 666 status = 2;
667 objnum = byte - '0'; 667 objnum = FXSYS_toDecimalDigit(byte);
668 } else if (byte == 't') { 668 } else if (byte == 't') {
669 status = 7; 669 status = 7;
670 inside_index = 1; 670 inside_index = 1;
671 } else if (byte == 'x') { 671 } else if (byte == 'x') {
672 status = 8; 672 status = 8;
673 inside_index = 1; 673 inside_index = 1;
674 } else { 674 } else {
675 --i; 675 --i;
676 status = 0; 676 status = 0;
677 } 677 }
678 break; 678 break;
679 case 2: 679 case 2:
680 if (byte <= '9' && byte >= '0') { 680 if (std::isdigit(byte)) {
681 objnum = objnum * 10 + byte - '0'; 681 objnum = objnum * 10 + FXSYS_toDecimalDigit(byte);
682 break; 682 break;
683 } else if (PDFCharIsWhitespace(byte)) { 683 } else if (PDFCharIsWhitespace(byte)) {
684 status = 3; 684 status = 3;
685 } else { 685 } else {
686 --i; 686 --i;
687 status = 14; 687 status = 14;
688 inside_index = 0; 688 inside_index = 0;
689 } 689 }
690 break; 690 break;
691 case 3: 691 case 3:
692 if (byte <= '9' && byte >= '0') { 692 if (std::isdigit(byte)) {
693 start_pos1 = pos + i; 693 start_pos1 = pos + i;
694 status = 4; 694 status = 4;
695 gennum = byte - '0'; 695 gennum = FXSYS_toDecimalDigit(byte);
696 } else if (PDFCharIsWhitespace(byte)) { 696 } else if (PDFCharIsWhitespace(byte)) {
697 break; 697 break;
698 } else if (byte == 't') { 698 } else if (byte == 't') {
699 status = 7; 699 status = 7;
700 inside_index = 1; 700 inside_index = 1;
701 } else { 701 } else {
702 --i; 702 --i;
703 status = 0; 703 status = 0;
704 } 704 }
705 break; 705 break;
706 case 4: 706 case 4:
707 if (byte <= '9' && byte >= '0') { 707 if (std::isdigit(byte)) {
708 gennum = gennum * 10 + byte - '0'; 708 gennum = gennum * 10 + FXSYS_toDecimalDigit(byte);
709 break; 709 break;
710 } else if (PDFCharIsWhitespace(byte)) { 710 } else if (PDFCharIsWhitespace(byte)) {
711 status = 5; 711 status = 5;
712 } else { 712 } else {
713 --i; 713 --i;
714 status = 0; 714 status = 0;
715 } 715 }
716 break; 716 break;
717 case 5: 717 case 5:
718 if (byte == 'o') { 718 if (byte == 'o') {
719 status = 6; 719 status = 6;
720 inside_index = 1; 720 inside_index = 1;
721 } else if (PDFCharIsWhitespace(byte)) { 721 } else if (PDFCharIsWhitespace(byte)) {
722 break; 722 break;
723 } else if (byte <= '9' && byte >= '0') { 723 } else if (std::isdigit(byte)) {
724 objnum = gennum; 724 objnum = gennum;
725 gennum = byte - '0'; 725 gennum = FXSYS_toDecimalDigit(byte);
726 start_pos = start_pos1; 726 start_pos = start_pos1;
727 start_pos1 = pos + i; 727 start_pos1 = pos + i;
728 status = 4; 728 status = 4;
729 } else if (byte == 't') { 729 } else if (byte == 't') {
730 status = 7; 730 status = 7;
731 inside_index = 1; 731 inside_index = 1;
732 } else { 732 } else {
733 --i; 733 --i;
734 status = 0; 734 status = 0;
735 } 735 }
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 parlevel++; 1856 parlevel++;
1857 buf.AppendChar('('); 1857 buf.AppendChar('(');
1858 } else if (ch == '\\') { 1858 } else if (ch == '\\') {
1859 status = 1; 1859 status = 1;
1860 } else { 1860 } else {
1861 buf.AppendChar(ch); 1861 buf.AppendChar(ch);
1862 } 1862 }
1863 break; 1863 break;
1864 case 1: 1864 case 1:
1865 if (ch >= '0' && ch <= '7') { 1865 if (ch >= '0' && ch <= '7') {
1866 iEscCode = ch - '0'; 1866 iEscCode = FXSYS_toDecimalDigit(ch);
1867 status = 2; 1867 status = 2;
1868 break; 1868 break;
1869 } 1869 }
1870 if (ch == 'n') { 1870 if (ch == 'n') {
1871 buf.AppendChar('\n'); 1871 buf.AppendChar('\n');
1872 } else if (ch == 'r') { 1872 } else if (ch == 'r') {
1873 buf.AppendChar('\r'); 1873 buf.AppendChar('\r');
1874 } else if (ch == 't') { 1874 } else if (ch == 't') {
1875 buf.AppendChar('\t'); 1875 buf.AppendChar('\t');
1876 } else if (ch == 'b') { 1876 } else if (ch == 'b') {
1877 buf.AppendChar('\b'); 1877 buf.AppendChar('\b');
1878 } else if (ch == 'f') { 1878 } else if (ch == 'f') {
1879 buf.AppendChar('\f'); 1879 buf.AppendChar('\f');
1880 } else if (ch == '\r') { 1880 } else if (ch == '\r') {
1881 status = 4; 1881 status = 4;
1882 break; 1882 break;
1883 } else if (ch == '\n') { 1883 } else if (ch == '\n') {
1884 } else { 1884 } else {
1885 buf.AppendChar(ch); 1885 buf.AppendChar(ch);
1886 } 1886 }
1887 status = 0; 1887 status = 0;
1888 break; 1888 break;
1889 case 2: 1889 case 2:
1890 if (ch >= '0' && ch <= '7') { 1890 if (ch >= '0' && ch <= '7') {
1891 iEscCode = iEscCode * 8 + ch - '0'; 1891 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
1892 status = 3; 1892 status = 3;
1893 } else { 1893 } else {
1894 buf.AppendChar(iEscCode); 1894 buf.AppendChar(iEscCode);
1895 status = 0; 1895 status = 0;
1896 continue; 1896 continue;
1897 } 1897 }
1898 break; 1898 break;
1899 case 3: 1899 case 3:
1900 if (ch >= '0' && ch <= '7') { 1900 if (ch >= '0' && ch <= '7') {
1901 iEscCode = iEscCode * 8 + ch - '0'; 1901 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
1902 buf.AppendChar(iEscCode); 1902 buf.AppendChar(iEscCode);
1903 status = 0; 1903 status = 0;
1904 } else { 1904 } else {
1905 buf.AppendChar(iEscCode); 1905 buf.AppendChar(iEscCode);
1906 status = 0; 1906 status = 0;
1907 continue; 1907 continue;
1908 } 1908 }
1909 break; 1909 break;
1910 case 4: 1910 case 4:
1911 status = 0; 1911 status = 0;
1912 if (ch != '\n') { 1912 if (ch != '\n') {
1913 continue; 1913 continue;
1914 } 1914 }
1915 break; 1915 break;
1916 } 1916 }
1917 if (!GetNextChar(ch)) { 1917 if (!GetNextChar(ch)) {
1918 break; 1918 break;
1919 } 1919 }
1920 } 1920 }
1921 GetNextChar(ch); 1921 GetNextChar(ch);
1922 return buf.GetByteString(); 1922 return buf.GetByteString();
1923 } 1923 }
1924 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { 1924 CFX_ByteString CPDF_SyntaxParser::ReadHexString() {
1925 uint8_t ch; 1925 uint8_t ch;
1926 if (!GetNextChar(ch)) { 1926 if (!GetNextChar(ch))
1927 return CFX_ByteString(); 1927 return CFX_ByteString();
1928 } 1928
1929 CFX_BinaryBuf buf; 1929 CFX_BinaryBuf buf;
1930 FX_BOOL bFirst = TRUE; 1930 bool bFirst = true;
1931 uint8_t code = 0; 1931 uint8_t code = 0;
1932 while (1) { 1932 while (1) {
1933 if (ch == '>') { 1933 if (ch == '>')
1934 break; 1934 break;
1935 } 1935
1936 if (ch >= '0' && ch <= '9') { 1936 if (std::isxdigit(ch)) {
1937 int val = FXSYS_toHexDigit(ch);
1937 if (bFirst) { 1938 if (bFirst) {
1938 code = (ch - '0') * 16; 1939 code = val * 16;
1939 } else { 1940 } else {
1940 code += ch - '0'; 1941 code += val;
1941 buf.AppendByte((uint8_t)code);
1942 }
1943 bFirst = !bFirst;
1944 } else if (ch >= 'A' && ch <= 'F') {
1945 if (bFirst) {
1946 code = (ch - 'A' + 10) * 16;
1947 } else {
1948 code += ch - 'A' + 10;
1949 buf.AppendByte((uint8_t)code);
1950 }
1951 bFirst = !bFirst;
1952 } else if (ch >= 'a' && ch <= 'f') {
1953 if (bFirst) {
1954 code = (ch - 'a' + 10) * 16;
1955 } else {
1956 code += ch - 'a' + 10;
1957 buf.AppendByte((uint8_t)code); 1942 buf.AppendByte((uint8_t)code);
1958 } 1943 }
1959 bFirst = !bFirst; 1944 bFirst = !bFirst;
1960 } 1945 }
1961 if (!GetNextChar(ch)) { 1946
1947 if (!GetNextChar(ch))
1962 break; 1948 break;
1963 }
1964 } 1949 }
1965 if (!bFirst) { 1950 if (!bFirst)
1966 buf.AppendByte((uint8_t)code); 1951 buf.AppendByte((uint8_t)code);
1967 } 1952
1968 return buf.GetByteString(); 1953 return buf.GetByteString();
1969 } 1954 }
1970 void CPDF_SyntaxParser::ToNextLine() { 1955 void CPDF_SyntaxParser::ToNextLine() {
1971 uint8_t ch; 1956 uint8_t ch;
1972 while (GetNextChar(ch)) { 1957 while (GetNextChar(ch)) {
1973 if (ch == '\n') { 1958 if (ch == '\n') {
1974 break; 1959 break;
1975 } 1960 }
1976 if (ch == '\r') { 1961 if (ch == '\r') {
1977 GetNextChar(ch); 1962 GetNextChar(ch);
(...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after
4953 if (!m_pLinearizedDict) 4938 if (!m_pLinearizedDict)
4954 return -1; 4939 return -1;
4955 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4940 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4956 if (!pRange) 4941 if (!pRange)
4957 return -1; 4942 return -1;
4958 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4943 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4959 if (!pStreamLen) 4944 if (!pStreamLen)
4960 return -1; 4945 return -1;
4961 return pStreamLen->GetInteger(); 4946 return pStreamLen->GetInteger();
4962 } 4947 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698