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

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

Issue 1638493002: Remove unused IsContentUsedElsewhere() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Revert to PS2. Created 4 years, 11 months 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
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 2022 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 return GetNextWord(nullptr); 2033 return GetNextWord(nullptr);
2034 } 2034 }
2035 2035
2036 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, 2036 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList,
2037 FX_DWORD objnum, 2037 FX_DWORD objnum,
2038 FX_DWORD gennum, 2038 FX_DWORD gennum,
2039 PARSE_CONTEXT* pContext, 2039 PARSE_CONTEXT* pContext,
2040 FX_BOOL bDecrypt) { 2040 FX_BOOL bDecrypt) {
2041 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); 2041 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
2042 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { 2042 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) {
2043 return NULL; 2043 return nullptr;
2044 } 2044 }
2045 FX_FILESIZE SavedPos = m_Pos; 2045 FX_FILESIZE SavedPos = m_Pos;
2046 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY);
2047 bool bIsNumber; 2046 bool bIsNumber;
2048 CFX_ByteString word = GetNextWord(&bIsNumber); 2047 CFX_ByteString word = GetNextWord(&bIsNumber);
2049 if (word.GetLength() == 0) { 2048 if (word.GetLength() == 0) {
2050 if (bTypeOnly) 2049 return nullptr;
2051 return (CPDF_Object*)PDFOBJ_INVALID;
2052 return NULL;
2053 } 2050 }
2054 if (bIsNumber) { 2051 if (bIsNumber) {
2055 FX_FILESIZE SavedPos = m_Pos; 2052 FX_FILESIZE SavedPos = m_Pos;
2056 CFX_ByteString nextword = GetNextWord(&bIsNumber); 2053 CFX_ByteString nextword = GetNextWord(&bIsNumber);
2057 if (bIsNumber) { 2054 if (bIsNumber) {
2058 CFX_ByteString nextword2 = GetNextWord(nullptr); 2055 CFX_ByteString nextword2 = GetNextWord(nullptr);
2059 if (nextword2 == "R") { 2056 if (nextword2 == "R") {
2060 FX_DWORD objnum = FXSYS_atoi(word); 2057 FX_DWORD objnum = FXSYS_atoi(word);
2061 if (bTypeOnly)
2062 return (CPDF_Object*)PDFOBJ_REFERENCE;
2063 return new CPDF_Reference(pObjList, objnum); 2058 return new CPDF_Reference(pObjList, objnum);
2064 } 2059 }
2065 } 2060 }
2066 m_Pos = SavedPos; 2061 m_Pos = SavedPos;
2067 if (bTypeOnly)
2068 return (CPDF_Object*)PDFOBJ_NUMBER;
2069 return new CPDF_Number(word); 2062 return new CPDF_Number(word);
2070 } 2063 }
2071 if (word == "true" || word == "false") { 2064 if (word == "true" || word == "false") {
2072 if (bTypeOnly)
2073 return (CPDF_Object*)PDFOBJ_BOOLEAN;
2074 return new CPDF_Boolean(word == "true"); 2065 return new CPDF_Boolean(word == "true");
2075 } 2066 }
2076 if (word == "null") { 2067 if (word == "null") {
2077 if (bTypeOnly)
2078 return (CPDF_Object*)PDFOBJ_NULL;
2079 return new CPDF_Null; 2068 return new CPDF_Null;
2080 } 2069 }
2081 if (word == "(") { 2070 if (word == "(") {
2082 if (bTypeOnly)
2083 return (CPDF_Object*)PDFOBJ_STRING;
2084 CFX_ByteString str = ReadString(); 2071 CFX_ByteString str = ReadString();
2085 if (m_pCryptoHandler && bDecrypt) { 2072 if (m_pCryptoHandler && bDecrypt) {
2086 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2073 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2087 } 2074 }
2088 return new CPDF_String(str, FALSE); 2075 return new CPDF_String(str, FALSE);
2089 } 2076 }
2090 if (word == "<") { 2077 if (word == "<") {
2091 if (bTypeOnly)
2092 return (CPDF_Object*)PDFOBJ_STRING;
2093 CFX_ByteString str = ReadHexString(); 2078 CFX_ByteString str = ReadHexString();
2094 if (m_pCryptoHandler && bDecrypt) { 2079 if (m_pCryptoHandler && bDecrypt) {
2095 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2080 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2096 } 2081 }
2097 return new CPDF_String(str, TRUE); 2082 return new CPDF_String(str, TRUE);
2098 } 2083 }
2099 if (word == "[") { 2084 if (word == "[") {
2100 if (bTypeOnly)
2101 return (CPDF_Object*)PDFOBJ_ARRAY;
2102 CPDF_Array* pArray = new CPDF_Array; 2085 CPDF_Array* pArray = new CPDF_Array;
2103 while (CPDF_Object* pObj = 2086 while (CPDF_Object* pObj =
2104 GetObject(pObjList, objnum, gennum, nullptr, true)) { 2087 GetObject(pObjList, objnum, gennum, nullptr, true)) {
2105 pArray->Add(pObj); 2088 pArray->Add(pObj);
2106 } 2089 }
2107 return pArray; 2090 return pArray;
2108 } 2091 }
2109 if (word[0] == '/') { 2092 if (word[0] == '/') {
2110 if (bTypeOnly)
2111 return (CPDF_Object*)PDFOBJ_NAME;
2112 return new CPDF_Name( 2093 return new CPDF_Name(
2113 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 2094 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
2114 } 2095 }
2115 if (word == "<<") { 2096 if (word == "<<") {
2116 if (bTypeOnly)
2117 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2118
2119 if (pContext) 2097 if (pContext)
2120 pContext->m_DictStart = SavedPos; 2098 pContext->m_DictStart = SavedPos;
2121 2099
2122 int32_t nKeys = 0; 2100 int32_t nKeys = 0;
2123 FX_FILESIZE dwSignValuePos = 0; 2101 FX_FILESIZE dwSignValuePos = 0;
2124 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 2102 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
2125 new CPDF_Dictionary); 2103 new CPDF_Dictionary);
2126 while (1) { 2104 while (1) {
2127 CFX_ByteString key = GetNextWord(nullptr); 2105 CFX_ByteString key = GetNextWord(nullptr);
2128 if (key.IsEmpty()) 2106 if (key.IsEmpty())
(...skipping 29 matching lines...) Expand all
2158 // Only when this is a signature dictionary and has contents, we reset the 2136 // Only when this is a signature dictionary and has contents, we reset the
2159 // contents to the un-decrypted form. 2137 // contents to the un-decrypted form.
2160 if (IsSignatureDict(pDict.get()) && dwSignValuePos) { 2138 if (IsSignatureDict(pDict.get()) && dwSignValuePos) {
2161 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); 2139 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos);
2162 m_Pos = dwSignValuePos; 2140 m_Pos = dwSignValuePos;
2163 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); 2141 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE);
2164 pDict->SetAt("Contents", pObj); 2142 pDict->SetAt("Contents", pObj);
2165 } 2143 }
2166 if (pContext) { 2144 if (pContext) {
2167 pContext->m_DictEnd = m_Pos; 2145 pContext->m_DictEnd = m_Pos;
2168 if (pContext->m_Flags & PDFPARSE_NOSTREAM) {
2169 return pDict.release();
2170 }
2171 } 2146 }
2172 FX_FILESIZE SavedPos = m_Pos; 2147 FX_FILESIZE SavedPos = m_Pos;
2173 CFX_ByteString nextword = GetNextWord(nullptr); 2148 CFX_ByteString nextword = GetNextWord(nullptr);
2174 if (nextword != "stream") { 2149 if (nextword != "stream") {
2175 m_Pos = SavedPos; 2150 m_Pos = SavedPos;
2176 return pDict.release(); 2151 return pDict.release();
2177 } 2152 }
2178
2179 return ReadStream(pDict.release(), pContext, objnum, gennum); 2153 return ReadStream(pDict.release(), pContext, objnum, gennum);
2180 } 2154 }
2181 if (word == ">>") { 2155 if (word == ">>") {
2182 m_Pos = SavedPos; 2156 m_Pos = SavedPos;
2183 return nullptr;
2184 } 2157 }
2185 if (bTypeOnly)
2186 return (CPDF_Object*)PDFOBJ_INVALID;
2187
2188 return nullptr; 2158 return nullptr;
2189 } 2159 }
2190 2160
2191 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( 2161 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict(
2192 CPDF_IndirectObjectHolder* pObjList, 2162 CPDF_IndirectObjectHolder* pObjList,
2193 FX_DWORD objnum, 2163 FX_DWORD objnum,
2194 FX_DWORD gennum, 2164 FX_DWORD gennum,
2195 PARSE_CONTEXT* pContext) { 2165 PARSE_CONTEXT* pContext) {
2196 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); 2166 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth);
2197 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { 2167 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) {
2198 return NULL; 2168 return nullptr;
2199 } 2169 }
2200 FX_FILESIZE SavedPos = m_Pos; 2170 FX_FILESIZE SavedPos = m_Pos;
2201 FX_BOOL bTypeOnly = pContext && (pContext->m_Flags & PDFPARSE_TYPEONLY);
2202 bool bIsNumber; 2171 bool bIsNumber;
2203 CFX_ByteString word = GetNextWord(&bIsNumber); 2172 CFX_ByteString word = GetNextWord(&bIsNumber);
2204 if (word.GetLength() == 0) { 2173 if (word.GetLength() == 0) {
2205 if (bTypeOnly)
2206 return (CPDF_Object*)PDFOBJ_INVALID;
2207 return nullptr; 2174 return nullptr;
2208 } 2175 }
2209 if (bIsNumber) { 2176 if (bIsNumber) {
2210 FX_FILESIZE SavedPos = m_Pos; 2177 FX_FILESIZE SavedPos = m_Pos;
2211 CFX_ByteString nextword = GetNextWord(&bIsNumber); 2178 CFX_ByteString nextword = GetNextWord(&bIsNumber);
2212 if (bIsNumber) { 2179 if (bIsNumber) {
2213 CFX_ByteString nextword2 = GetNextWord(nullptr); 2180 CFX_ByteString nextword2 = GetNextWord(nullptr);
2214 if (nextword2 == "R") { 2181 if (nextword2 == "R") {
2215 if (bTypeOnly) 2182 return new CPDF_Reference(pObjList, FXSYS_atoi(word));
2216 return (CPDF_Object*)PDFOBJ_REFERENCE;
2217 FX_DWORD objnum = FXSYS_atoi(word);
2218 return new CPDF_Reference(pObjList, objnum);
2219 } 2183 }
2220 } 2184 }
2221 m_Pos = SavedPos; 2185 m_Pos = SavedPos;
2222 if (bTypeOnly)
2223 return (CPDF_Object*)PDFOBJ_NUMBER;
2224 return new CPDF_Number(word); 2186 return new CPDF_Number(word);
2225 } 2187 }
2226 if (word == "true" || word == "false") { 2188 if (word == "true" || word == "false") {
2227 if (bTypeOnly)
2228 return (CPDF_Object*)PDFOBJ_BOOLEAN;
2229 return new CPDF_Boolean(word == "true"); 2189 return new CPDF_Boolean(word == "true");
2230 } 2190 }
2231 if (word == "null") { 2191 if (word == "null") {
2232 if (bTypeOnly)
2233 return (CPDF_Object*)PDFOBJ_NULL;
2234 return new CPDF_Null; 2192 return new CPDF_Null;
2235 } 2193 }
2236 if (word == "(") { 2194 if (word == "(") {
2237 if (bTypeOnly)
2238 return (CPDF_Object*)PDFOBJ_STRING;
2239 CFX_ByteString str = ReadString(); 2195 CFX_ByteString str = ReadString();
2240 if (m_pCryptoHandler) 2196 if (m_pCryptoHandler)
2241 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2197 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2242 return new CPDF_String(str, FALSE); 2198 return new CPDF_String(str, FALSE);
2243 } 2199 }
2244 if (word == "<") { 2200 if (word == "<") {
2245 if (bTypeOnly)
2246 return (CPDF_Object*)PDFOBJ_STRING;
2247 CFX_ByteString str = ReadHexString(); 2201 CFX_ByteString str = ReadHexString();
2248 if (m_pCryptoHandler) 2202 if (m_pCryptoHandler)
2249 m_pCryptoHandler->Decrypt(objnum, gennum, str); 2203 m_pCryptoHandler->Decrypt(objnum, gennum, str);
2250 return new CPDF_String(str, TRUE); 2204 return new CPDF_String(str, TRUE);
2251 } 2205 }
2252 if (word == "[") { 2206 if (word == "[") {
2253 if (bTypeOnly)
2254 return (CPDF_Object*)PDFOBJ_ARRAY;
2255 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( 2207 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray(
2256 new CPDF_Array); 2208 new CPDF_Array);
2257 while (CPDF_Object* pObj = 2209 while (CPDF_Object* pObj =
2258 GetObject(pObjList, objnum, gennum, nullptr, true)) { 2210 GetObject(pObjList, objnum, gennum, nullptr, true)) {
2259 pArray->Add(pObj); 2211 pArray->Add(pObj);
2260 } 2212 }
2261 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; 2213 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr;
2262 } 2214 }
2263 if (word[0] == '/') { 2215 if (word[0] == '/') {
2264 if (bTypeOnly)
2265 return (CPDF_Object*)PDFOBJ_NAME;
2266 return new CPDF_Name( 2216 return new CPDF_Name(
2267 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 2217 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
2268 } 2218 }
2269 if (word == "<<") { 2219 if (word == "<<") {
2270 if (bTypeOnly)
2271 return (CPDF_Object*)PDFOBJ_DICTIONARY;
2272 if (pContext) 2220 if (pContext)
2273 pContext->m_DictStart = SavedPos; 2221 pContext->m_DictStart = SavedPos;
2274 2222
2275 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( 2223 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict(
2276 new CPDF_Dictionary); 2224 new CPDF_Dictionary);
2277 while (1) { 2225 while (1) {
2278 FX_FILESIZE SavedPos = m_Pos; 2226 FX_FILESIZE SavedPos = m_Pos;
2279 CFX_ByteString key = GetNextWord(nullptr); 2227 CFX_ByteString key = GetNextWord(nullptr);
2280 if (key.IsEmpty()) 2228 if (key.IsEmpty())
2281 return nullptr; 2229 return nullptr;
(...skipping 17 matching lines...) Expand all
2299 } 2247 }
2300 return nullptr; 2248 return nullptr;
2301 } 2249 }
2302 if (key.GetLength() > 1) { 2250 if (key.GetLength() > 1) {
2303 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), 2251 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1),
2304 obj.release()); 2252 obj.release());
2305 } 2253 }
2306 } 2254 }
2307 if (pContext) { 2255 if (pContext) {
2308 pContext->m_DictEnd = m_Pos; 2256 pContext->m_DictEnd = m_Pos;
2309 if (pContext->m_Flags & PDFPARSE_NOSTREAM) {
2310 return pDict.release();
2311 }
2312 } 2257 }
2313 FX_FILESIZE SavedPos = m_Pos; 2258 FX_FILESIZE SavedPos = m_Pos;
2314 CFX_ByteString nextword = GetNextWord(nullptr); 2259 CFX_ByteString nextword = GetNextWord(nullptr);
2315 if (nextword != "stream") { 2260 if (nextword != "stream") {
2316 m_Pos = SavedPos; 2261 m_Pos = SavedPos;
2317 return pDict.release(); 2262 return pDict.release();
2318 } 2263 }
2319 2264
2320 return ReadStream(pDict.release(), pContext, objnum, gennum); 2265 return ReadStream(pDict.release(), pContext, objnum, gennum);
2321 } 2266 }
2322 if (word == ">>") { 2267 if (word == ">>") {
2323 m_Pos = SavedPos; 2268 m_Pos = SavedPos;
2324 return nullptr;
2325 } 2269 }
2326 if (bTypeOnly)
2327 return (CPDF_Object*)PDFOBJ_INVALID;
2328 return nullptr; 2270 return nullptr;
2329 } 2271 }
2330 2272
2331 unsigned int CPDF_SyntaxParser::ReadEOLMarkers(FX_FILESIZE pos) { 2273 unsigned int CPDF_SyntaxParser::ReadEOLMarkers(FX_FILESIZE pos) {
2332 unsigned char byte1 = 0; 2274 unsigned char byte1 = 0;
2333 unsigned char byte2 = 0; 2275 unsigned char byte2 = 0;
2334 GetCharAt(pos, byte1); 2276 GetCharAt(pos, byte1);
2335 GetCharAt(pos + 1, byte2); 2277 GetCharAt(pos + 1, byte2);
2336 unsigned int markers = 0; 2278 unsigned int markers = 0;
2337 if (byte1 == '\r' && byte2 == '\n') { 2279 if (byte1 == '\r' && byte2 == '\n') {
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4980 if (!m_pLinearizedDict) 4922 if (!m_pLinearizedDict)
4981 return -1; 4923 return -1;
4982 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); 4924 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H");
4983 if (!pRange) 4925 if (!pRange)
4984 return -1; 4926 return -1;
4985 CPDF_Object* pStreamLen = pRange->GetElementValue(1); 4927 CPDF_Object* pStreamLen = pRange->GetElementValue(1);
4986 if (!pStreamLen) 4928 if (!pStreamLen)
4987 return -1; 4929 return -1;
4988 return pStreamLen->GetInteger(); 4930 return pStreamLen->GetInteger();
4989 } 4931 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698