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