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

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

Issue 1431683008: 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"
17 #include "../../../include/fxcrt/fx_safe_types.h" 16 #include "../../../include/fxcrt/fx_safe_types.h"
18 #include "../fpdf_page/pageint.h" 17 #include "../fpdf_page/pageint.h"
19 #include "parser_int.h" 18 #include "parser_int.h"
20 19
21 namespace { 20 namespace {
22 21
23 struct SearchTagRecord { 22 struct SearchTagRecord {
24 const uint8_t* m_pTag; 23 const uint8_t* m_pTag;
25 FX_DWORD m_Len; 24 FX_DWORD m_Len;
26 FX_DWORD m_Offset; 25 FX_DWORD m_Offset;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 156 }
158 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); 157 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler();
159 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); 158 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*);
160 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, 159 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess,
161 FX_BOOL bReParse, 160 FX_BOOL bReParse,
162 FX_BOOL bOwnFileRead) { 161 FX_BOOL bOwnFileRead) {
163 CloseParser(bReParse); 162 CloseParser(bReParse);
164 m_bXRefStream = FALSE; 163 m_bXRefStream = FALSE;
165 m_LastXRefOffset = 0; 164 m_LastXRefOffset = 0;
166 m_bOwnFileRead = bOwnFileRead; 165 m_bOwnFileRead = bOwnFileRead;
167
168 int32_t offset = GetHeaderOffset(pFileAccess); 166 int32_t offset = GetHeaderOffset(pFileAccess);
169 if (offset == -1) { 167 if (offset == -1) {
170 if (bOwnFileRead && pFileAccess) 168 if (bOwnFileRead && pFileAccess) {
171 pFileAccess->Release(); 169 pFileAccess->Release();
170 }
172 return PDFPARSE_ERROR_FORMAT; 171 return PDFPARSE_ERROR_FORMAT;
173 } 172 }
174 m_Syntax.InitParser(pFileAccess, offset); 173 m_Syntax.InitParser(pFileAccess, offset);
175
176 uint8_t ch; 174 uint8_t ch;
177 if (!m_Syntax.GetCharAt(5, ch)) 175 if (!m_Syntax.GetCharAt(5, ch)) {
178 return PDFPARSE_ERROR_FORMAT; 176 return PDFPARSE_ERROR_FORMAT;
179 if (std::isdigit(ch)) 177 }
180 m_FileVersion = FXSYS_toDecimalDigit(ch) * 10; 178 if (ch >= '0' && ch <= '9') {
181 179 m_FileVersion = (ch - '0') * 10;
182 if (!m_Syntax.GetCharAt(7, ch)) 180 }
181 if (!m_Syntax.GetCharAt(7, ch)) {
183 return PDFPARSE_ERROR_FORMAT; 182 return PDFPARSE_ERROR_FORMAT;
184 if (std::isdigit(ch)) 183 }
185 m_FileVersion += FXSYS_toDecimalDigit(ch); 184 if (ch >= '0' && ch <= '9') {
186 185 m_FileVersion += ch - '0';
187 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) 186 }
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) 200 if (pResult == NULL) {
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() || m_pDocument->GetPageCount() == 0) { 229 if (m_pDocument->GetRoot() == NULL || 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()) 242 if (m_pDocument->GetRoot() == NULL) {
243 return PDFPARSE_ERROR_FORMAT; 243 return PDFPARSE_ERROR_FORMAT;
244 }
244 } 245 }
245 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), 246 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(),
246 sizeof(FX_FILESIZE), CompareFileSize); 247 sizeof(FX_FILESIZE), CompareFileSize);
247 FX_DWORD RootObjNum = GetRootObjNum(); 248 FX_DWORD RootObjNum = GetRootObjNum();
248 if (RootObjNum == 0) { 249 if (RootObjNum == 0) {
249 ReleaseEncryptHandler(); 250 ReleaseEncryptHandler();
250 RebuildCrossRef(); 251 RebuildCrossRef();
251 RootObjNum = GetRootObjNum(); 252 RootObjNum = GetRootObjNum();
252 if (RootObjNum == 0) 253 if (RootObjNum == 0) {
253 return PDFPARSE_ERROR_FORMAT; 254 return PDFPARSE_ERROR_FORMAT;
254 255 }
255 dwRet = SetEncryptHandler(); 256 dwRet = SetEncryptHandler();
256 if (dwRet != PDFPARSE_ERROR_SUCCESS) 257 if (dwRet != PDFPARSE_ERROR_SUCCESS) {
257 return dwRet; 258 return dwRet;
259 }
258 } 260 }
259 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { 261 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) {
260 CPDF_Reference* pMetadata = 262 CPDF_Reference* pMetadata =
261 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); 263 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata")));
262 if (pMetadata) 264 if (pMetadata)
263 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); 265 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum();
264 } 266 }
265 return PDFPARSE_ERROR_SUCCESS; 267 return PDFPARSE_ERROR_SUCCESS;
266 } 268 }
267 FX_DWORD CPDF_Parser::SetEncryptHandler() { 269 FX_DWORD CPDF_Parser::SetEncryptHandler() {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 for (int32_t i = 0; i < block_size; i++) { 453 for (int32_t i = 0; i < block_size; i++) {
452 FX_DWORD objnum = start_objnum + block * 1024 + i; 454 FX_DWORD objnum = start_objnum + block * 1024 + i;
453 char* pEntry = pBuf + i * recordsize; 455 char* pEntry = pBuf + i * recordsize;
454 if (pEntry[17] == 'f') { 456 if (pEntry[17] == 'f') {
455 m_CrossRef.SetAtGrow(objnum, 0); 457 m_CrossRef.SetAtGrow(objnum, 0);
456 m_V5Type.SetAtGrow(objnum, 0); 458 m_V5Type.SetAtGrow(objnum, 0);
457 } else { 459 } else {
458 int32_t offset = FXSYS_atoi(pEntry); 460 int32_t offset = FXSYS_atoi(pEntry);
459 if (offset == 0) { 461 if (offset == 0) {
460 for (int32_t c = 0; c < 10; c++) { 462 for (int32_t c = 0; c < 10; c++) {
461 if (!std::isdigit(pEntry[c])) 463 if (pEntry[c] < '0' || pEntry[c] > '9') {
462 return FALSE; 464 return FALSE;
465 }
463 } 466 }
464 } 467 }
465 m_CrossRef.SetAtGrow(objnum, offset); 468 m_CrossRef.SetAtGrow(objnum, offset);
466 int32_t version = FXSYS_atoi(pEntry + 11); 469 int32_t version = FXSYS_atoi(pEntry + 11);
467 if (version >= 1) { 470 if (version >= 1) {
468 m_bVersionUpdated = TRUE; 471 m_bVersionUpdated = TRUE;
469 } 472 }
470 m_ObjVersion.SetAtGrow(objnum, version); 473 m_ObjVersion.SetAtGrow(objnum, version);
471 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { 474 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) {
472 void* pResult = FXSYS_bsearch( 475 void* pResult = FXSYS_bsearch(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 start_objnum--; 554 start_objnum--;
552 objnum = 0; 555 objnum = 0;
553 } 556 }
554 } 557 }
555 m_CrossRef.SetAtGrow(objnum, 0); 558 m_CrossRef.SetAtGrow(objnum, 0);
556 m_V5Type.SetAtGrow(objnum, 0); 559 m_V5Type.SetAtGrow(objnum, 0);
557 } else { 560 } else {
558 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); 561 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry);
559 if (offset == 0) { 562 if (offset == 0) {
560 for (int32_t c = 0; c < 10; c++) { 563 for (int32_t c = 0; c < 10; c++) {
561 if (!std::isdigit(pEntry[c])) 564 if (pEntry[c] < '0' || pEntry[c] > '9') {
562 return false; 565 return false;
566 }
563 } 567 }
564 } 568 }
565 m_CrossRef.SetAtGrow(objnum, offset); 569 m_CrossRef.SetAtGrow(objnum, offset);
566 int32_t version = FXSYS_atoi(pEntry + 11); 570 int32_t version = FXSYS_atoi(pEntry + 11);
567 if (version >= 1) { 571 if (version >= 1) {
568 m_bVersionUpdated = TRUE; 572 m_bVersionUpdated = TRUE;
569 } 573 }
570 m_ObjVersion.SetAtGrow(objnum, version); 574 m_ObjVersion.SetAtGrow(objnum, version);
571 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && 575 if (m_CrossRef[objnum] < m_Syntax.m_FileLen &&
572 !FindPosInOffsets(m_CrossRef[objnum])) { 576 !FindPosInOffsets(m_CrossRef[objnum])) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 if (size > 4096) { 624 if (size > 4096) {
621 size = 4096; 625 size = 4096;
622 } 626 }
623 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { 627 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) {
624 break; 628 break;
625 } 629 }
626 for (FX_DWORD i = 0; i < size; i++) { 630 for (FX_DWORD i = 0; i < size; i++) {
627 uint8_t byte = buffer[i]; 631 uint8_t byte = buffer[i];
628 switch (status) { 632 switch (status) {
629 case 0: 633 case 0:
630 if (PDFCharIsWhitespace(byte)) 634 if (PDFCharIsWhitespace(byte)) {
631 status = 1; 635 status = 1;
632 636 }
633 if (std::isdigit(byte)) { 637 if (byte <= '9' && byte >= '0') {
634 --i; 638 --i;
635 status = 1; 639 status = 1;
636 } 640 }
637
638 if (byte == '%') { 641 if (byte == '%') {
639 inside_index = 0; 642 inside_index = 0;
640 status = 9; 643 status = 9;
641 } 644 }
642
643 if (byte == '(') { 645 if (byte == '(') {
644 status = 10; 646 status = 10;
645 depth = 1; 647 depth = 1;
646 } 648 }
647
648 if (byte == '<') { 649 if (byte == '<') {
649 inside_index = 1; 650 inside_index = 1;
650 status = 11; 651 status = 11;
651 } 652 }
652 653 if (byte == '\\') {
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 (std::isdigit(byte)) { 664 } else if (byte <= '9' && byte >= '0') {
665 start_pos = pos + i; 665 start_pos = pos + i;
666 status = 2; 666 status = 2;
667 objnum = FXSYS_toDecimalDigit(byte); 667 objnum = byte - '0';
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 (std::isdigit(byte)) { 680 if (byte <= '9' && byte >= '0') {
681 objnum = objnum * 10 + FXSYS_toDecimalDigit(byte); 681 objnum = objnum * 10 + byte - '0';
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 (std::isdigit(byte)) { 692 if (byte <= '9' && byte >= '0') {
693 start_pos1 = pos + i; 693 start_pos1 = pos + i;
694 status = 4; 694 status = 4;
695 gennum = FXSYS_toDecimalDigit(byte); 695 gennum = byte - '0';
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 (std::isdigit(byte)) { 707 if (byte <= '9' && byte >= '0') {
708 gennum = gennum * 10 + FXSYS_toDecimalDigit(byte); 708 gennum = gennum * 10 + byte - '0';
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 (std::isdigit(byte)) { 723 } else if (byte <= '9' && byte >= '0') {
724 objnum = gennum; 724 objnum = gennum;
725 gennum = FXSYS_toDecimalDigit(byte); 725 gennum = byte - '0';
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 = FXSYS_toDecimalDigit(ch); 1866 iEscCode = ch - '0';
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 + FXSYS_toDecimalDigit(ch); 1891 iEscCode = iEscCode * 8 + ch - '0';
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 + FXSYS_toDecimalDigit(ch); 1901 iEscCode = iEscCode * 8 + ch - '0';
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 bool bFirst = true; 1930 FX_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 (std::isxdigit(ch)) { 1936 if (ch >= '0' && ch <= '9') {
1937 int val = FXSYS_toHexDigit(ch);
1938 if (bFirst) { 1937 if (bFirst) {
1939 code = val * 16; 1938 code = (ch - '0') * 16;
1940 } else { 1939 } else {
1941 code += val; 1940 code += ch - '0';
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;
1942 buf.AppendByte((uint8_t)code); 1957 buf.AppendByte((uint8_t)code);
1943 } 1958 }
1944 bFirst = !bFirst; 1959 bFirst = !bFirst;
1945 } 1960 }
1946 1961 if (!GetNextChar(ch)) {
1947 if (!GetNextChar(ch))
1948 break; 1962 break;
1963 }
1949 } 1964 }
1950 if (!bFirst) 1965 if (!bFirst) {
1951 buf.AppendByte((uint8_t)code); 1966 buf.AppendByte((uint8_t)code);
1952 1967 }
1953 return buf.GetByteString(); 1968 return buf.GetByteString();
1954 } 1969 }
1955 void CPDF_SyntaxParser::ToNextLine() { 1970 void CPDF_SyntaxParser::ToNextLine() {
1956 uint8_t ch; 1971 uint8_t ch;
1957 while (GetNextChar(ch)) { 1972 while (GetNextChar(ch)) {
1958 if (ch == '\n') { 1973 if (ch == '\n') {
1959 break; 1974 break;
1960 } 1975 }
1961 if (ch == '\r') { 1976 if (ch == '\r') {
1962 GetNextChar(ch); 1977 GetNextChar(ch);
(...skipping 2975 matching lines...) Expand 10 before | Expand all | Expand 10 after
4938 if (!m_pLinearizedDict) 4953 if (!m_pLinearizedDict)
4939 return -1; 4954 return -1;
4940 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H")); 4955 CPDF_Array* pRange = m_pLinearizedDict->GetArray(FX_BSTRC("H"));
4941 if (!pRange) 4956 if (!pRange)
4942 return -1; 4957 return -1;
4943 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4958 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4944 if (!pStreamLen) 4959 if (!pStreamLen)
4945 return -1; 4960 return -1;
4946 return pStreamLen->GetInteger(); 4961 return pStreamLen->GetInteger();
4947 } 4962 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_utility.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698