Chromium Code Reviews| 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 <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 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 struct SearchTagRecord { | 22 struct SearchTagRecord { |
| 22 const uint8_t* m_pTag; | 23 const uint8_t* m_pTag; |
| 23 FX_DWORD m_Len; | 24 FX_DWORD m_Len; |
| 24 FX_DWORD m_Offset; | 25 FX_DWORD m_Offset; |
| 25 }; | 26 }; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 } | 156 } |
| 156 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); | 157 CPDF_SecurityHandler* FPDF_CreateStandardSecurityHandler(); |
| 157 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); | 158 CPDF_SecurityHandler* FPDF_CreatePubKeyHandler(void*); |
| 158 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, | 159 FX_DWORD CPDF_Parser::StartParse(IFX_FileRead* pFileAccess, |
| 159 FX_BOOL bReParse, | 160 FX_BOOL bReParse, |
| 160 FX_BOOL bOwnFileRead) { | 161 FX_BOOL bOwnFileRead) { |
| 161 CloseParser(bReParse); | 162 CloseParser(bReParse); |
| 162 m_bXRefStream = FALSE; | 163 m_bXRefStream = FALSE; |
| 163 m_LastXRefOffset = 0; | 164 m_LastXRefOffset = 0; |
| 164 m_bOwnFileRead = bOwnFileRead; | 165 m_bOwnFileRead = bOwnFileRead; |
| 166 | |
| 165 int32_t offset = GetHeaderOffset(pFileAccess); | 167 int32_t offset = GetHeaderOffset(pFileAccess); |
| 166 if (offset == -1) { | 168 if (offset == -1) { |
| 167 if (bOwnFileRead && pFileAccess) { | 169 if (bOwnFileRead && pFileAccess) |
| 168 pFileAccess->Release(); | 170 pFileAccess->Release(); |
| 169 } | |
| 170 return PDFPARSE_ERROR_FORMAT; | 171 return PDFPARSE_ERROR_FORMAT; |
| 171 } | 172 } |
| 172 m_Syntax.InitParser(pFileAccess, offset); | 173 m_Syntax.InitParser(pFileAccess, offset); |
| 174 | |
| 173 uint8_t ch; | 175 uint8_t ch; |
| 174 if (!m_Syntax.GetCharAt(5, ch)) { | 176 if (!m_Syntax.GetCharAt(5, ch)) |
| 175 return PDFPARSE_ERROR_FORMAT; | 177 return PDFPARSE_ERROR_FORMAT; |
| 176 } | 178 if (std::isdigit(ch)) |
| 177 if (ch >= '0' && ch <= '9') { | |
| 178 m_FileVersion = (ch - '0') * 10; | 179 m_FileVersion = (ch - '0') * 10; |
| 179 } | 180 |
| 180 if (!m_Syntax.GetCharAt(7, ch)) { | 181 if (!m_Syntax.GetCharAt(7, ch)) |
| 181 return PDFPARSE_ERROR_FORMAT; | 182 return PDFPARSE_ERROR_FORMAT; |
| 182 } | 183 if (std::isdigit(ch)) |
| 183 if (ch >= '0' && ch <= '9') { | |
| 184 m_FileVersion += ch - '0'; | 184 m_FileVersion += ch - '0'; |
| 185 } | 185 |
| 186 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) { | 186 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) |
| 187 return PDFPARSE_ERROR_FORMAT; | 187 return PDFPARSE_ERROR_FORMAT; |
| 188 } | 188 |
| 189 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); | 189 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); |
| 190 if (!bReParse) { | 190 if (!bReParse) |
| 191 m_pDocument = new CPDF_Document(this); | 191 m_pDocument = new CPDF_Document(this); |
| 192 } | 192 |
| 193 FX_BOOL bXRefRebuilt = FALSE; | 193 FX_BOOL bXRefRebuilt = FALSE; |
| 194 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) { | 194 if (m_Syntax.SearchWord(FX_BSTRC("startxref"), TRUE, FALSE, 4096)) { |
| 195 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); | 195 FX_FILESIZE startxref_offset = m_Syntax.SavePos(); |
| 196 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), | 196 void* pResult = FXSYS_bsearch(&startxref_offset, m_SortedOffset.GetData(), |
| 197 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 197 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
| 198 CompareFileSize); | 198 CompareFileSize); |
| 199 if (pResult == NULL) { | 199 if (!pResult) |
| 200 m_SortedOffset.Add(startxref_offset); | 200 m_SortedOffset.Add(startxref_offset); |
| 201 } | 201 |
| 202 m_Syntax.GetKeyword(); | 202 m_Syntax.GetKeyword(); |
| 203 FX_BOOL bNumber; | 203 FX_BOOL bNumber; |
| 204 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); | 204 CFX_ByteString xrefpos_str = m_Syntax.GetNextWord(bNumber); |
| 205 if (!bNumber) { | 205 if (!bNumber) |
| 206 return PDFPARSE_ERROR_FORMAT; | 206 return PDFPARSE_ERROR_FORMAT; |
| 207 } | 207 |
| 208 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); | 208 m_LastXRefOffset = (FX_FILESIZE)FXSYS_atoi64(xrefpos_str); |
| 209 if (!LoadAllCrossRefV4(m_LastXRefOffset) && | 209 if (!LoadAllCrossRefV4(m_LastXRefOffset) && |
| 210 !LoadAllCrossRefV5(m_LastXRefOffset)) { | 210 !LoadAllCrossRefV5(m_LastXRefOffset)) { |
| 211 if (!RebuildCrossRef()) { | 211 if (!RebuildCrossRef()) |
| 212 return PDFPARSE_ERROR_FORMAT; | 212 return PDFPARSE_ERROR_FORMAT; |
| 213 } | 213 |
| 214 bXRefRebuilt = TRUE; | 214 bXRefRebuilt = TRUE; |
| 215 m_LastXRefOffset = 0; | 215 m_LastXRefOffset = 0; |
| 216 } | 216 } |
| 217 } else { | 217 } else { |
| 218 if (!RebuildCrossRef()) { | 218 if (!RebuildCrossRef()) |
| 219 return PDFPARSE_ERROR_FORMAT; | 219 return PDFPARSE_ERROR_FORMAT; |
| 220 } | 220 |
| 221 bXRefRebuilt = TRUE; | 221 bXRefRebuilt = TRUE; |
| 222 } | 222 } |
| 223 FX_DWORD dwRet = SetEncryptHandler(); | 223 FX_DWORD dwRet = SetEncryptHandler(); |
| 224 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 224 if (dwRet != PDFPARSE_ERROR_SUCCESS) |
| 225 return dwRet; | 225 return dwRet; |
| 226 } | 226 |
| 227 m_pDocument->LoadDoc(); | 227 m_pDocument->LoadDoc(); |
| 228 if (m_pDocument->GetRoot() == NULL || m_pDocument->GetPageCount() == 0) { | 228 if (!m_pDocument->GetRoot() || m_pDocument->GetPageCount() == 0) { |
| 229 if (bXRefRebuilt) { | 229 if (bXRefRebuilt) |
| 230 return PDFPARSE_ERROR_FORMAT; | 230 return PDFPARSE_ERROR_FORMAT; |
| 231 } | 231 |
| 232 ReleaseEncryptHandler(); | 232 ReleaseEncryptHandler(); |
| 233 if (!RebuildCrossRef()) { | 233 if (!RebuildCrossRef()) |
| 234 return PDFPARSE_ERROR_FORMAT; | 234 return PDFPARSE_ERROR_FORMAT; |
| 235 } | 235 |
| 236 dwRet = SetEncryptHandler(); | 236 dwRet = SetEncryptHandler(); |
| 237 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 237 if (dwRet != PDFPARSE_ERROR_SUCCESS) |
| 238 return dwRet; | 238 return dwRet; |
| 239 } | 239 |
| 240 m_pDocument->LoadDoc(); | 240 m_pDocument->LoadDoc(); |
| 241 if (m_pDocument->GetRoot() == NULL) { | 241 if (!m_pDocument->GetRoot()) |
| 242 return PDFPARSE_ERROR_FORMAT; | 242 return PDFPARSE_ERROR_FORMAT; |
| 243 } | |
| 244 } | 243 } |
| 245 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 244 FXSYS_qsort(m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
| 246 sizeof(FX_FILESIZE), CompareFileSize); | 245 sizeof(FX_FILESIZE), CompareFileSize); |
| 247 FX_DWORD RootObjNum = GetRootObjNum(); | 246 FX_DWORD RootObjNum = GetRootObjNum(); |
| 248 if (RootObjNum == 0) { | 247 if (RootObjNum == 0) { |
| 249 ReleaseEncryptHandler(); | 248 ReleaseEncryptHandler(); |
| 250 RebuildCrossRef(); | 249 RebuildCrossRef(); |
| 251 RootObjNum = GetRootObjNum(); | 250 RootObjNum = GetRootObjNum(); |
| 252 if (RootObjNum == 0) { | 251 if (RootObjNum == 0) |
| 253 return PDFPARSE_ERROR_FORMAT; | 252 return PDFPARSE_ERROR_FORMAT; |
| 254 } | 253 |
| 255 dwRet = SetEncryptHandler(); | 254 dwRet = SetEncryptHandler(); |
| 256 if (dwRet != PDFPARSE_ERROR_SUCCESS) { | 255 if (dwRet != PDFPARSE_ERROR_SUCCESS) |
| 257 return dwRet; | 256 return dwRet; |
| 258 } | |
| 259 } | 257 } |
| 260 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { | 258 if (m_pSecurityHandler && !m_pSecurityHandler->IsMetadataEncrypted()) { |
| 261 CPDF_Reference* pMetadata = | 259 CPDF_Reference* pMetadata = |
| 262 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); | 260 ToReference(m_pDocument->GetRoot()->GetElement(FX_BSTRC("Metadata"))); |
| 263 if (pMetadata) | 261 if (pMetadata) |
| 264 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); | 262 m_Syntax.m_MetadataObjnum = pMetadata->GetRefObjNum(); |
| 265 } | 263 } |
| 266 return PDFPARSE_ERROR_SUCCESS; | 264 return PDFPARSE_ERROR_SUCCESS; |
| 267 } | 265 } |
| 268 FX_DWORD CPDF_Parser::SetEncryptHandler() { | 266 FX_DWORD CPDF_Parser::SetEncryptHandler() { |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 for (int32_t i = 0; i < block_size; i++) { | 450 for (int32_t i = 0; i < block_size; i++) { |
| 453 FX_DWORD objnum = start_objnum + block * 1024 + i; | 451 FX_DWORD objnum = start_objnum + block * 1024 + i; |
| 454 char* pEntry = pBuf + i * recordsize; | 452 char* pEntry = pBuf + i * recordsize; |
| 455 if (pEntry[17] == 'f') { | 453 if (pEntry[17] == 'f') { |
| 456 m_CrossRef.SetAtGrow(objnum, 0); | 454 m_CrossRef.SetAtGrow(objnum, 0); |
| 457 m_V5Type.SetAtGrow(objnum, 0); | 455 m_V5Type.SetAtGrow(objnum, 0); |
| 458 } else { | 456 } else { |
| 459 int32_t offset = FXSYS_atoi(pEntry); | 457 int32_t offset = FXSYS_atoi(pEntry); |
| 460 if (offset == 0) { | 458 if (offset == 0) { |
| 461 for (int32_t c = 0; c < 10; c++) { | 459 for (int32_t c = 0; c < 10; c++) { |
| 462 if (pEntry[c] < '0' || pEntry[c] > '9') { | 460 if (!std::isdigit(pEntry[c])) |
| 463 return FALSE; | 461 return FALSE; |
| 464 } | |
| 465 } | 462 } |
| 466 } | 463 } |
| 467 m_CrossRef.SetAtGrow(objnum, offset); | 464 m_CrossRef.SetAtGrow(objnum, offset); |
| 468 int32_t version = FXSYS_atoi(pEntry + 11); | 465 int32_t version = FXSYS_atoi(pEntry + 11); |
| 469 if (version >= 1) { | 466 if (version >= 1) { |
| 470 m_bVersionUpdated = TRUE; | 467 m_bVersionUpdated = TRUE; |
| 471 } | 468 } |
| 472 m_ObjVersion.SetAtGrow(objnum, version); | 469 m_ObjVersion.SetAtGrow(objnum, version); |
| 473 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { | 470 if (m_CrossRef[objnum] < m_Syntax.m_FileLen) { |
| 474 void* pResult = FXSYS_bsearch( | 471 void* pResult = FXSYS_bsearch( |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 start_objnum--; | 550 start_objnum--; |
| 554 objnum = 0; | 551 objnum = 0; |
| 555 } | 552 } |
| 556 } | 553 } |
| 557 m_CrossRef.SetAtGrow(objnum, 0); | 554 m_CrossRef.SetAtGrow(objnum, 0); |
| 558 m_V5Type.SetAtGrow(objnum, 0); | 555 m_V5Type.SetAtGrow(objnum, 0); |
| 559 } else { | 556 } else { |
| 560 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); | 557 FX_FILESIZE offset = (FX_FILESIZE)FXSYS_atoi64(pEntry); |
| 561 if (offset == 0) { | 558 if (offset == 0) { |
| 562 for (int32_t c = 0; c < 10; c++) { | 559 for (int32_t c = 0; c < 10; c++) { |
| 563 if (pEntry[c] < '0' || pEntry[c] > '9') { | 560 if (!std::isdigit(pEntry[c])) |
| 564 return false; | 561 return false; |
| 565 } | |
| 566 } | 562 } |
| 567 } | 563 } |
| 568 m_CrossRef.SetAtGrow(objnum, offset); | 564 m_CrossRef.SetAtGrow(objnum, offset); |
| 569 int32_t version = FXSYS_atoi(pEntry + 11); | 565 int32_t version = FXSYS_atoi(pEntry + 11); |
| 570 if (version >= 1) { | 566 if (version >= 1) { |
| 571 m_bVersionUpdated = TRUE; | 567 m_bVersionUpdated = TRUE; |
| 572 } | 568 } |
| 573 m_ObjVersion.SetAtGrow(objnum, version); | 569 m_ObjVersion.SetAtGrow(objnum, version); |
| 574 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && | 570 if (m_CrossRef[objnum] < m_Syntax.m_FileLen && |
| 575 !FindPosInOffsets(m_CrossRef[objnum])) { | 571 !FindPosInOffsets(m_CrossRef[objnum])) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 if (size > 4096) { | 619 if (size > 4096) { |
| 624 size = 4096; | 620 size = 4096; |
| 625 } | 621 } |
| 626 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { | 622 if (!m_Syntax.m_pFileAccess->ReadBlock(buffer, pos, size)) { |
| 627 break; | 623 break; |
| 628 } | 624 } |
| 629 for (FX_DWORD i = 0; i < size; i++) { | 625 for (FX_DWORD i = 0; i < size; i++) { |
| 630 uint8_t byte = buffer[i]; | 626 uint8_t byte = buffer[i]; |
| 631 switch (status) { | 627 switch (status) { |
| 632 case 0: | 628 case 0: |
| 633 if (PDFCharIsWhitespace(byte)) { | 629 if (PDFCharIsWhitespace(byte)) |
| 634 status = 1; | 630 status = 1; |
| 635 } | 631 |
| 636 if (byte <= '9' && byte >= '0') { | 632 if (std::isdigit(byte)) { |
| 637 --i; | 633 --i; |
| 638 status = 1; | 634 status = 1; |
| 639 } | 635 } |
| 636 | |
| 640 if (byte == '%') { | 637 if (byte == '%') { |
| 641 inside_index = 0; | 638 inside_index = 0; |
| 642 status = 9; | 639 status = 9; |
| 643 } | 640 } |
| 641 | |
| 644 if (byte == '(') { | 642 if (byte == '(') { |
| 645 status = 10; | 643 status = 10; |
| 646 depth = 1; | 644 depth = 1; |
| 647 } | 645 } |
| 646 | |
| 648 if (byte == '<') { | 647 if (byte == '<') { |
| 649 inside_index = 1; | 648 inside_index = 1; |
| 650 status = 11; | 649 status = 11; |
| 651 } | 650 } |
| 652 if (byte == '\\') { | 651 |
| 652 if (byte == '\\') | |
| 653 status = 13; | 653 status = 13; |
| 654 } | 654 |
| 655 if (byte == 't') { | 655 if (byte == 't') { |
| 656 status = 7; | 656 status = 7; |
| 657 inside_index = 1; | 657 inside_index = 1; |
| 658 } | 658 } |
| 659 break; | 659 break; |
| 660 case 1: | 660 case 1: |
| 661 if (PDFCharIsWhitespace(byte)) { | 661 if (PDFCharIsWhitespace(byte)) { |
| 662 break; | 662 break; |
| 663 } else if (byte <= '9' && byte >= '0') { | 663 } else if (std::isdigit(byte)) { |
| 664 start_pos = pos + i; | 664 start_pos = pos + i; |
| 665 status = 2; | 665 status = 2; |
| 666 objnum = byte - '0'; | 666 objnum = byte - '0'; |
| 667 } else if (byte == 't') { | 667 } else if (byte == 't') { |
| 668 status = 7; | 668 status = 7; |
| 669 inside_index = 1; | 669 inside_index = 1; |
| 670 } else if (byte == 'x') { | 670 } else if (byte == 'x') { |
| 671 status = 8; | 671 status = 8; |
| 672 inside_index = 1; | 672 inside_index = 1; |
| 673 } else { | 673 } else { |
| 674 --i; | 674 --i; |
| 675 status = 0; | 675 status = 0; |
| 676 } | 676 } |
| 677 break; | 677 break; |
| 678 case 2: | 678 case 2: |
| 679 if (byte <= '9' && byte >= '0') { | 679 if (std::isdigit(byte)) { |
| 680 objnum = objnum * 10 + byte - '0'; | 680 objnum = objnum * 10 + byte - '0'; |
| 681 break; | 681 break; |
| 682 } else if (PDFCharIsWhitespace(byte)) { | 682 } else if (PDFCharIsWhitespace(byte)) { |
| 683 status = 3; | 683 status = 3; |
| 684 } else { | 684 } else { |
| 685 --i; | 685 --i; |
| 686 status = 14; | 686 status = 14; |
| 687 inside_index = 0; | 687 inside_index = 0; |
| 688 } | 688 } |
| 689 break; | 689 break; |
| 690 case 3: | 690 case 3: |
| 691 if (byte <= '9' && byte >= '0') { | 691 if (std::isdigit(byte)) { |
| 692 start_pos1 = pos + i; | 692 start_pos1 = pos + i; |
| 693 status = 4; | 693 status = 4; |
| 694 gennum = byte - '0'; | 694 gennum = byte - '0'; |
| 695 } else if (PDFCharIsWhitespace(byte)) { | 695 } else if (PDFCharIsWhitespace(byte)) { |
| 696 break; | 696 break; |
| 697 } else if (byte == 't') { | 697 } else if (byte == 't') { |
| 698 status = 7; | 698 status = 7; |
| 699 inside_index = 1; | 699 inside_index = 1; |
| 700 } else { | 700 } else { |
| 701 --i; | 701 --i; |
| 702 status = 0; | 702 status = 0; |
| 703 } | 703 } |
| 704 break; | 704 break; |
| 705 case 4: | 705 case 4: |
| 706 if (byte <= '9' && byte >= '0') { | 706 if (std::isdigit(byte)) { |
| 707 gennum = gennum * 10 + byte - '0'; | 707 gennum = gennum * 10 + byte - '0'; |
| 708 break; | 708 break; |
| 709 } else if (PDFCharIsWhitespace(byte)) { | 709 } else if (PDFCharIsWhitespace(byte)) { |
| 710 status = 5; | 710 status = 5; |
| 711 } else { | 711 } else { |
| 712 --i; | 712 --i; |
| 713 status = 0; | 713 status = 0; |
| 714 } | 714 } |
| 715 break; | 715 break; |
| 716 case 5: | 716 case 5: |
| 717 if (byte == 'o') { | 717 if (byte == 'o') { |
| 718 status = 6; | 718 status = 6; |
| 719 inside_index = 1; | 719 inside_index = 1; |
| 720 } else if (PDFCharIsWhitespace(byte)) { | 720 } else if (PDFCharIsWhitespace(byte)) { |
| 721 break; | 721 break; |
| 722 } else if (byte <= '9' && byte >= '0') { | 722 } else if (std::isdigit(byte)) { |
| 723 objnum = gennum; | 723 objnum = gennum; |
| 724 gennum = byte - '0'; | 724 gennum = byte - '0'; |
| 725 start_pos = start_pos1; | 725 start_pos = start_pos1; |
| 726 start_pos1 = pos + i; | 726 start_pos1 = pos + i; |
| 727 status = 4; | 727 status = 4; |
| 728 } else if (byte == 't') { | 728 } else if (byte == 't') { |
| 729 status = 7; | 729 status = 7; |
| 730 inside_index = 1; | 730 inside_index = 1; |
| 731 } else { | 731 } else { |
| 732 --i; | 732 --i; |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 } | 1913 } |
| 1914 break; | 1914 break; |
| 1915 } | 1915 } |
| 1916 if (!GetNextChar(ch)) { | 1916 if (!GetNextChar(ch)) { |
| 1917 break; | 1917 break; |
| 1918 } | 1918 } |
| 1919 } | 1919 } |
| 1920 GetNextChar(ch); | 1920 GetNextChar(ch); |
| 1921 return buf.GetByteString(); | 1921 return buf.GetByteString(); |
| 1922 } | 1922 } |
| 1923 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { | 1923 CFX_ByteString CPDF_SyntaxParser::ReadHexString() { |
|
Tom Sepez
2015/10/29 19:28:31
ditto for test.
dsinclair
2015/11/03 15:59:02
https://codereview.chromium.org/1433503002/
| |
| 1924 uint8_t ch; | 1924 uint8_t ch; |
| 1925 if (!GetNextChar(ch)) { | 1925 if (!GetNextChar(ch)) |
| 1926 return CFX_ByteString(); | 1926 return CFX_ByteString(); |
| 1927 } | 1927 |
| 1928 CFX_BinaryBuf buf; | 1928 CFX_BinaryBuf buf; |
| 1929 FX_BOOL bFirst = TRUE; | 1929 FX_BOOL bFirst = TRUE; |
| 1930 uint8_t code = 0; | 1930 uint8_t code = 0; |
| 1931 while (1) { | 1931 while (1) { |
| 1932 if (ch == '>') { | 1932 if (ch == '>') |
| 1933 break; | 1933 break; |
| 1934 } | 1934 |
| 1935 if (ch >= '0' && ch <= '9') { | 1935 if (std::isxdigit(ch)) { |
| 1936 int val = HexCharToDigit(ch); | |
| 1936 if (bFirst) { | 1937 if (bFirst) { |
| 1937 code = (ch - '0') * 16; | 1938 code = val * 16; |
| 1938 } else { | 1939 } else { |
| 1939 code += ch - '0'; | 1940 code += val; |
| 1940 buf.AppendByte((uint8_t)code); | |
| 1941 } | |
| 1942 bFirst = !bFirst; | |
| 1943 } else if (ch >= 'A' && ch <= 'F') { | |
| 1944 if (bFirst) { | |
| 1945 code = (ch - 'A' + 10) * 16; | |
| 1946 } else { | |
| 1947 code += ch - 'A' + 10; | |
| 1948 buf.AppendByte((uint8_t)code); | |
| 1949 } | |
| 1950 bFirst = !bFirst; | |
| 1951 } else if (ch >= 'a' && ch <= 'f') { | |
| 1952 if (bFirst) { | |
| 1953 code = (ch - 'a' + 10) * 16; | |
| 1954 } else { | |
| 1955 code += ch - 'a' + 10; | |
| 1956 buf.AppendByte((uint8_t)code); | 1941 buf.AppendByte((uint8_t)code); |
| 1957 } | 1942 } |
| 1958 bFirst = !bFirst; | 1943 bFirst = !bFirst; |
| 1959 } | 1944 } |
| 1960 if (!GetNextChar(ch)) { | 1945 |
| 1946 if (!GetNextChar(ch)) | |
| 1961 break; | 1947 break; |
| 1962 } | |
| 1963 } | 1948 } |
| 1964 if (!bFirst) { | 1949 if (!bFirst) |
| 1965 buf.AppendByte((uint8_t)code); | 1950 buf.AppendByte((uint8_t)code); |
| 1966 } | 1951 |
| 1967 return buf.GetByteString(); | 1952 return buf.GetByteString(); |
| 1968 } | 1953 } |
| 1969 void CPDF_SyntaxParser::ToNextLine() { | 1954 void CPDF_SyntaxParser::ToNextLine() { |
| 1970 uint8_t ch; | 1955 uint8_t ch; |
| 1971 while (GetNextChar(ch)) { | 1956 while (GetNextChar(ch)) { |
| 1972 if (ch == '\n') { | 1957 if (ch == '\n') { |
| 1973 break; | 1958 break; |
| 1974 } | 1959 } |
| 1975 if (ch == '\r') { | 1960 if (ch == '\r') { |
| 1976 GetNextChar(ch); | 1961 GetNextChar(ch); |
| (...skipping 2562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4539 return FALSE; | 4524 return FALSE; |
| 4540 } | 4525 } |
| 4541 CPDF_PageNode::~CPDF_PageNode() { | 4526 CPDF_PageNode::~CPDF_PageNode() { |
| 4542 int32_t iSize = m_childNode.GetSize(); | 4527 int32_t iSize = m_childNode.GetSize(); |
| 4543 for (int32_t i = 0; i < iSize; ++i) { | 4528 for (int32_t i = 0; i < iSize; ++i) { |
| 4544 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; | 4529 CPDF_PageNode* pNode = (CPDF_PageNode*)m_childNode[i]; |
| 4545 delete pNode; | 4530 delete pNode; |
| 4546 } | 4531 } |
| 4547 m_childNode.RemoveAll(); | 4532 m_childNode.RemoveAll(); |
| 4548 } | 4533 } |
| OLD | NEW |