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 "core/include/fpdfapi/fpdf_parser.h" | 7 #include "core/include/fpdfapi/fpdf_parser.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if (pFileAccess) | 201 if (pFileAccess) |
202 pFileAccess->Release(); | 202 pFileAccess->Release(); |
203 return FORMAT_ERROR; | 203 return FORMAT_ERROR; |
204 } | 204 } |
205 m_Syntax.InitParser(pFileAccess, offset); | 205 m_Syntax.InitParser(pFileAccess, offset); |
206 | 206 |
207 uint8_t ch; | 207 uint8_t ch; |
208 if (!m_Syntax.GetCharAt(5, ch)) | 208 if (!m_Syntax.GetCharAt(5, ch)) |
209 return FORMAT_ERROR; | 209 return FORMAT_ERROR; |
210 if (std::isdigit(ch)) | 210 if (std::isdigit(ch)) |
211 m_FileVersion = FXSYS_toDecimalDigit(ch) * 10; | 211 m_FileVersion = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)) * 10; |
212 | 212 |
213 if (!m_Syntax.GetCharAt(7, ch)) | 213 if (!m_Syntax.GetCharAt(7, ch)) |
214 return FORMAT_ERROR; | 214 return FORMAT_ERROR; |
215 if (std::isdigit(ch)) | 215 if (std::isdigit(ch)) |
216 m_FileVersion += FXSYS_toDecimalDigit(ch); | 216 m_FileVersion += FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)); |
217 | 217 |
218 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) | 218 if (m_Syntax.m_FileLen < m_Syntax.m_HeaderOffset + 9) |
219 return FORMAT_ERROR; | 219 return FORMAT_ERROR; |
220 | 220 |
221 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); | 221 m_Syntax.RestorePos(m_Syntax.m_FileLen - m_Syntax.m_HeaderOffset - 9); |
222 m_pDocument = new CPDF_Document(this); | 222 m_pDocument = new CPDF_Document(this); |
223 | 223 |
224 FX_BOOL bXRefRebuilt = FALSE; | 224 FX_BOOL bXRefRebuilt = FALSE; |
225 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { | 225 if (m_Syntax.SearchWord("startxref", TRUE, FALSE, 4096)) { |
226 m_SortedOffset.insert(m_Syntax.SavePos()); | 226 m_SortedOffset.insert(m_Syntax.SavePos()); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 } else if (byte == 't') { | 662 } else if (byte == 't') { |
663 state = ParserState::kTrailer; | 663 state = ParserState::kTrailer; |
664 inside_index = 1; | 664 inside_index = 1; |
665 } | 665 } |
666 break; | 666 break; |
667 | 667 |
668 case ParserState::kWhitespace: | 668 case ParserState::kWhitespace: |
669 if (std::isdigit(byte)) { | 669 if (std::isdigit(byte)) { |
670 start_pos = pos + i; | 670 start_pos = pos + i; |
671 state = ParserState::kObjNum; | 671 state = ParserState::kObjNum; |
672 objnum = FXSYS_toDecimalDigit(byte); | 672 objnum = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(byte)); |
673 } else if (byte == 't') { | 673 } else if (byte == 't') { |
674 state = ParserState::kTrailer; | 674 state = ParserState::kTrailer; |
675 inside_index = 1; | 675 inside_index = 1; |
676 } else if (byte == 'x') { | 676 } else if (byte == 'x') { |
677 state = ParserState::kXref; | 677 state = ParserState::kXref; |
678 inside_index = 1; | 678 inside_index = 1; |
679 } else if (!PDFCharIsWhitespace(byte)) { | 679 } else if (!PDFCharIsWhitespace(byte)) { |
680 --i; | 680 --i; |
681 state = ParserState::kDefault; | 681 state = ParserState::kDefault; |
682 } | 682 } |
683 break; | 683 break; |
684 | 684 |
685 case ParserState::kObjNum: | 685 case ParserState::kObjNum: |
686 if (std::isdigit(byte)) { | 686 if (std::isdigit(byte)) { |
687 objnum = objnum * 10 + FXSYS_toDecimalDigit(byte); | 687 objnum = |
| 688 objnum * 10 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(byte)); |
688 } else if (PDFCharIsWhitespace(byte)) { | 689 } else if (PDFCharIsWhitespace(byte)) { |
689 state = ParserState::kPostObjNum; | 690 state = ParserState::kPostObjNum; |
690 } else { | 691 } else { |
691 --i; | 692 --i; |
692 state = ParserState::kEndObj; | 693 state = ParserState::kEndObj; |
693 inside_index = 0; | 694 inside_index = 0; |
694 } | 695 } |
695 break; | 696 break; |
696 | 697 |
697 case ParserState::kPostObjNum: | 698 case ParserState::kPostObjNum: |
698 if (std::isdigit(byte)) { | 699 if (std::isdigit(byte)) { |
699 start_pos1 = pos + i; | 700 start_pos1 = pos + i; |
700 state = ParserState::kGenNum; | 701 state = ParserState::kGenNum; |
701 gennum = FXSYS_toDecimalDigit(byte); | 702 gennum = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(byte)); |
702 } else if (byte == 't') { | 703 } else if (byte == 't') { |
703 state = ParserState::kTrailer; | 704 state = ParserState::kTrailer; |
704 inside_index = 1; | 705 inside_index = 1; |
705 } else if (!PDFCharIsWhitespace(byte)) { | 706 } else if (!PDFCharIsWhitespace(byte)) { |
706 --i; | 707 --i; |
707 state = ParserState::kDefault; | 708 state = ParserState::kDefault; |
708 } | 709 } |
709 break; | 710 break; |
710 | 711 |
711 case ParserState::kGenNum: | 712 case ParserState::kGenNum: |
712 if (std::isdigit(byte)) { | 713 if (std::isdigit(byte)) { |
713 gennum = gennum * 10 + FXSYS_toDecimalDigit(byte); | 714 gennum = |
| 715 gennum * 10 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(byte)); |
714 } else if (PDFCharIsWhitespace(byte)) { | 716 } else if (PDFCharIsWhitespace(byte)) { |
715 state = ParserState::kPostGenNum; | 717 state = ParserState::kPostGenNum; |
716 } else { | 718 } else { |
717 --i; | 719 --i; |
718 state = ParserState::kDefault; | 720 state = ParserState::kDefault; |
719 } | 721 } |
720 break; | 722 break; |
721 | 723 |
722 case ParserState::kPostGenNum: | 724 case ParserState::kPostGenNum: |
723 if (byte == 'o') { | 725 if (byte == 'o') { |
724 state = ParserState::kBeginObj; | 726 state = ParserState::kBeginObj; |
725 inside_index = 1; | 727 inside_index = 1; |
726 } else if (std::isdigit(byte)) { | 728 } else if (std::isdigit(byte)) { |
727 objnum = gennum; | 729 objnum = gennum; |
728 gennum = FXSYS_toDecimalDigit(byte); | 730 gennum = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(byte)); |
729 start_pos = start_pos1; | 731 start_pos = start_pos1; |
730 start_pos1 = pos + i; | 732 start_pos1 = pos + i; |
731 state = ParserState::kGenNum; | 733 state = ParserState::kGenNum; |
732 } else if (byte == 't') { | 734 } else if (byte == 't') { |
733 state = ParserState::kTrailer; | 735 state = ParserState::kTrailer; |
734 inside_index = 1; | 736 inside_index = 1; |
735 } else if (!PDFCharIsWhitespace(byte)) { | 737 } else if (!PDFCharIsWhitespace(byte)) { |
736 --i; | 738 --i; |
737 state = ParserState::kDefault; | 739 state = ParserState::kDefault; |
738 } | 740 } |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 parlevel++; | 1871 parlevel++; |
1870 buf.AppendChar('('); | 1872 buf.AppendChar('('); |
1871 } else if (ch == '\\') { | 1873 } else if (ch == '\\') { |
1872 status = 1; | 1874 status = 1; |
1873 } else { | 1875 } else { |
1874 buf.AppendChar(ch); | 1876 buf.AppendChar(ch); |
1875 } | 1877 } |
1876 break; | 1878 break; |
1877 case 1: | 1879 case 1: |
1878 if (ch >= '0' && ch <= '7') { | 1880 if (ch >= '0' && ch <= '7') { |
1879 iEscCode = FXSYS_toDecimalDigit(ch); | 1881 iEscCode = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)); |
1880 status = 2; | 1882 status = 2; |
1881 break; | 1883 break; |
1882 } | 1884 } |
1883 | 1885 |
1884 if (ch == 'n') { | 1886 if (ch == 'n') { |
1885 buf.AppendChar('\n'); | 1887 buf.AppendChar('\n'); |
1886 } else if (ch == 'r') { | 1888 } else if (ch == 'r') { |
1887 buf.AppendChar('\r'); | 1889 buf.AppendChar('\r'); |
1888 } else if (ch == 't') { | 1890 } else if (ch == 't') { |
1889 buf.AppendChar('\t'); | 1891 buf.AppendChar('\t'); |
1890 } else if (ch == 'b') { | 1892 } else if (ch == 'b') { |
1891 buf.AppendChar('\b'); | 1893 buf.AppendChar('\b'); |
1892 } else if (ch == 'f') { | 1894 } else if (ch == 'f') { |
1893 buf.AppendChar('\f'); | 1895 buf.AppendChar('\f'); |
1894 } else if (ch == '\r') { | 1896 } else if (ch == '\r') { |
1895 status = 4; | 1897 status = 4; |
1896 break; | 1898 break; |
1897 } else if (ch != '\n') { | 1899 } else if (ch != '\n') { |
1898 buf.AppendChar(ch); | 1900 buf.AppendChar(ch); |
1899 } | 1901 } |
1900 status = 0; | 1902 status = 0; |
1901 break; | 1903 break; |
1902 case 2: | 1904 case 2: |
1903 if (ch >= '0' && ch <= '7') { | 1905 if (ch >= '0' && ch <= '7') { |
1904 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch); | 1906 iEscCode = |
| 1907 iEscCode * 8 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)); |
1905 status = 3; | 1908 status = 3; |
1906 } else { | 1909 } else { |
1907 buf.AppendChar(iEscCode); | 1910 buf.AppendChar(iEscCode); |
1908 status = 0; | 1911 status = 0; |
1909 continue; | 1912 continue; |
1910 } | 1913 } |
1911 break; | 1914 break; |
1912 case 3: | 1915 case 3: |
1913 if (ch >= '0' && ch <= '7') { | 1916 if (ch >= '0' && ch <= '7') { |
1914 iEscCode = iEscCode * 8 + FXSYS_toDecimalDigit(ch); | 1917 iEscCode = |
| 1918 iEscCode * 8 + FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)); |
1915 buf.AppendChar(iEscCode); | 1919 buf.AppendChar(iEscCode); |
1916 status = 0; | 1920 status = 0; |
1917 } else { | 1921 } else { |
1918 buf.AppendChar(iEscCode); | 1922 buf.AppendChar(iEscCode); |
1919 status = 0; | 1923 status = 0; |
1920 continue; | 1924 continue; |
1921 } | 1925 } |
1922 break; | 1926 break; |
1923 case 4: | 1927 case 4: |
1924 status = 0; | 1928 status = 0; |
(...skipping 3101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5026 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); | 5030 CPDF_Array* pRange = m_pLinearizedDict->GetArrayBy("H"); |
5027 if (!pRange) | 5031 if (!pRange) |
5028 return -1; | 5032 return -1; |
5029 | 5033 |
5030 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 5034 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
5031 if (!pStreamLen) | 5035 if (!pStreamLen) |
5032 return -1; | 5036 return -1; |
5033 | 5037 |
5034 return pStreamLen->GetInteger(); | 5038 return pStreamLen->GetInteger(); |
5035 } | 5039 } |
OLD | NEW |