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

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 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 parlevel++; 1849 parlevel++;
1850 buf.AppendChar('('); 1850 buf.AppendChar('(');
1851 } else if (ch == '\\') { 1851 } else if (ch == '\\') {
1852 status = 1; 1852 status = 1;
1853 } else { 1853 } else {
1854 buf.AppendChar(ch); 1854 buf.AppendChar(ch);
1855 } 1855 }
1856 break; 1856 break;
1857 case 1: 1857 case 1:
1858 if (ch >= '0' && ch <= '7') { 1858 if (ch >= '0' && ch <= '7') {
1859 iEscCode = ch - '0'; 1859 iEscCode = FXSYS_toDecimalDigit(ch);
1860 status = 2; 1860 status = 2;
1861 break; 1861 break;
1862 } 1862 }
1863 if (ch == 'n') { 1863 if (ch == 'n') {
1864 buf.AppendChar('\n'); 1864 buf.AppendChar('\n');
1865 } else if (ch == 'r') { 1865 } else if (ch == 'r') {
1866 buf.AppendChar('\r'); 1866 buf.AppendChar('\r');
1867 } else if (ch == 't') { 1867 } else if (ch == 't') {
1868 buf.AppendChar('\t'); 1868 buf.AppendChar('\t');
1869 } else if (ch == 'b') { 1869 } else if (ch == 'b') {
1870 buf.AppendChar('\b'); 1870 buf.AppendChar('\b');
1871 } else if (ch == 'f') { 1871 } else if (ch == 'f') {
1872 buf.AppendChar('\f'); 1872 buf.AppendChar('\f');
1873 } else if (ch == '\r') { 1873 } else if (ch == '\r') {
1874 status = 4; 1874 status = 4;
1875 break; 1875 break;
1876 } else if (ch == '\n') { 1876 } else if (ch == '\n') {
1877 } else { 1877 } else {
1878 buf.AppendChar(ch); 1878 buf.AppendChar(ch);
1879 } 1879 }
1880 status = 0; 1880 status = 0;
1881 break; 1881 break;
1882 case 2: 1882 case 2:
1883 if (ch >= '0' && ch <= '7') { 1883 if (ch >= '0' && ch <= '7') {
1884 iEscCode = iEscCode * 8 + ch - '0'; 1884 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
1885 status = 3; 1885 status = 3;
1886 } else { 1886 } else {
1887 buf.AppendChar(iEscCode); 1887 buf.AppendChar(iEscCode);
1888 status = 0; 1888 status = 0;
1889 continue; 1889 continue;
1890 } 1890 }
1891 break; 1891 break;
1892 case 3: 1892 case 3:
1893 if (ch >= '0' && ch <= '7') { 1893 if (ch >= '0' && ch <= '7') {
1894 iEscCode = iEscCode * 8 + ch - '0'; 1894 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch);
1895 buf.AppendChar(iEscCode); 1895 buf.AppendChar(iEscCode);
1896 status = 0; 1896 status = 0;
1897 } else { 1897 } else {
1898 buf.AppendChar(iEscCode); 1898 buf.AppendChar(iEscCode);
1899 status = 0; 1899 status = 0;
1900 continue; 1900 continue;
1901 } 1901 }
1902 break; 1902 break;
1903 case 4: 1903 case 4:
1904 status = 0; 1904 status = 0;
1905 if (ch != '\n') { 1905 if (ch != '\n') {
1906 continue; 1906 continue;
1907 } 1907 }
1908 break; 1908 break;
1909 } 1909 }
1910 if (!GetNextChar(ch)) { 1910 if (!GetNextChar(ch)) {
1911 break; 1911 break;
1912 } 1912 }
1913 } 1913 }
1914 GetNextChar(ch); 1914 GetNextChar(ch);
1915 return buf.GetByteString(); 1915 return buf.GetByteString();
1916 } 1916 }
1917 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { 1917 CFX_ByteString CPDF_SyntaxParser::ReadHexString() {
1918 uint8_t ch; 1918 uint8_t ch;
1919 if (!GetNextChar(ch)) { 1919 if (!GetNextChar(ch))
1920 return CFX_ByteString(); 1920 return CFX_ByteString();
1921 } 1921
1922 CFX_BinaryBuf buf; 1922 CFX_BinaryBuf buf;
1923 FX_BOOL bFirst = TRUE; 1923 bool bFirst = true;
1924 uint8_t code = 0; 1924 uint8_t code = 0;
1925 while (1) { 1925 while (1) {
1926 if (ch == '>') { 1926 if (ch == '>')
1927 break; 1927 break;
1928 } 1928
1929 if (ch >= '0' && ch <= '9') { 1929 if (std::isxdigit(ch)) {
1930 int val = FXSYS_toHexDigit(ch);
1930 if (bFirst) { 1931 if (bFirst) {
1931 code = (ch - '0') * 16; 1932 code = val * 16;
1932 } else { 1933 } else {
1933 code += ch - '0'; 1934 code += val;
1934 buf.AppendByte((uint8_t)code);
1935 }
1936 bFirst = !bFirst;
1937 } else if (ch >= 'A' && ch <= 'F') {
1938 if (bFirst) {
1939 code = (ch - 'A' + 10) * 16;
1940 } else {
1941 code += ch - 'A' + 10;
1942 buf.AppendByte((uint8_t)code);
1943 }
1944 bFirst = !bFirst;
1945 } else if (ch >= 'a' && ch <= 'f') {
1946 if (bFirst) {
1947 code = (ch - 'a' + 10) * 16;
1948 } else {
1949 code += ch - 'a' + 10;
1950 buf.AppendByte((uint8_t)code); 1935 buf.AppendByte((uint8_t)code);
1951 } 1936 }
1952 bFirst = !bFirst; 1937 bFirst = !bFirst;
1953 } 1938 }
1954 if (!GetNextChar(ch)) { 1939
1940 if (!GetNextChar(ch))
1955 break; 1941 break;
1956 }
1957 } 1942 }
1958 if (!bFirst) { 1943 if (!bFirst)
1959 buf.AppendByte((uint8_t)code); 1944 buf.AppendByte((uint8_t)code);
1960 } 1945
1961 return buf.GetByteString(); 1946 return buf.GetByteString();
1962 } 1947 }
1963 void CPDF_SyntaxParser::ToNextLine() { 1948 void CPDF_SyntaxParser::ToNextLine() {
1964 uint8_t ch; 1949 uint8_t ch;
1965 while (GetNextChar(ch)) { 1950 while (GetNextChar(ch)) {
1966 if (ch == '\n') { 1951 if (ch == '\n') {
1967 break; 1952 break;
1968 } 1953 }
1969 if (ch == '\r') { 1954 if (ch == '\r') {
1970 GetNextChar(ch); 1955 GetNextChar(ch);
(...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after
4946 if (!m_pLinearizedDict) 4931 if (!m_pLinearizedDict)
4947 return -1; 4932 return -1;
4948 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4933 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4949 if (!pRange) 4934 if (!pRange)
4950 return -1; 4935 return -1;
4951 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4936 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4952 if (!pStreamLen) 4937 if (!pStreamLen)
4953 return -1; 4938 return -1;
4954 return pStreamLen->GetInteger(); 4939 return pStreamLen->GetInteger();
4955 } 4940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698