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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 ReleaseEncryptHandler(); | 289 ReleaseEncryptHandler(); |
290 SetEncryptDictionary(NULL); | 290 SetEncryptDictionary(NULL); |
291 if (!m_pTrailer) { | 291 if (!m_pTrailer) { |
292 return PDFPARSE_ERROR_FORMAT; | 292 return PDFPARSE_ERROR_FORMAT; |
293 } | 293 } |
294 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); | 294 CPDF_Object* pEncryptObj = m_pTrailer->GetElement("Encrypt"); |
295 if (pEncryptObj) { | 295 if (pEncryptObj) { |
296 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { | 296 if (CPDF_Dictionary* pEncryptDict = pEncryptObj->AsDictionary()) { |
297 SetEncryptDictionary(pEncryptDict); | 297 SetEncryptDictionary(pEncryptDict); |
298 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { | 298 } else if (CPDF_Reference* pRef = pEncryptObj->AsReference()) { |
299 pEncryptObj = | 299 pEncryptObj = m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
300 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr); | |
301 if (pEncryptObj) | 300 if (pEncryptObj) |
302 SetEncryptDictionary(pEncryptObj->GetDict()); | 301 SetEncryptDictionary(pEncryptObj->GetDict()); |
303 } | 302 } |
304 } | 303 } |
305 if (m_bForceUseSecurityHandler) { | 304 if (m_bForceUseSecurityHandler) { |
306 FX_DWORD err = PDFPARSE_ERROR_HANDLER; | 305 FX_DWORD err = PDFPARSE_ERROR_HANDLER; |
307 if (!m_pSecurityHandler) { | 306 if (!m_pSecurityHandler) { |
308 return PDFPARSE_ERROR_HANDLER; | 307 return PDFPARSE_ERROR_HANDLER; |
309 } | 308 } |
310 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { | 309 if (!m_pSecurityHandler->OnInit(this, m_pEncryptDict)) { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 last_obj = start_pos; | 781 last_obj = start_pos; |
783 void* pResult = | 782 void* pResult = |
784 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), | 783 FXSYS_bsearch(&obj_pos, m_SortedOffset.GetData(), |
785 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), | 784 m_SortedOffset.GetSize(), sizeof(FX_FILESIZE), |
786 CompareFileSize); | 785 CompareFileSize); |
787 if (!pResult) { | 786 if (!pResult) { |
788 m_SortedOffset.Add(obj_pos); | 787 m_SortedOffset.Add(obj_pos); |
789 } | 788 } |
790 FX_FILESIZE obj_end = 0; | 789 FX_FILESIZE obj_end = 0; |
791 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( | 790 CPDF_Object* pObject = ParseIndirectObjectAtByStrict( |
792 m_pDocument, obj_pos, objnum, NULL, &obj_end); | 791 m_pDocument, obj_pos, objnum, &obj_end); |
793 if (CPDF_Stream* pStream = ToStream(pObject)) { | 792 if (CPDF_Stream* pStream = ToStream(pObject)) { |
794 if (CPDF_Dictionary* pDict = pStream->GetDict()) { | 793 if (CPDF_Dictionary* pDict = pStream->GetDict()) { |
795 if ((pDict->KeyExist("Type")) && | 794 if ((pDict->KeyExist("Type")) && |
796 (pDict->GetString("Type") == "XRef" && | 795 (pDict->GetString("Type") == "XRef" && |
797 pDict->KeyExist("Size"))) { | 796 pDict->KeyExist("Size"))) { |
798 CPDF_Object* pRoot = pDict->GetElement("Root"); | 797 CPDF_Object* pRoot = pDict->GetElement("Root"); |
799 if (pRoot && pRoot->GetDict() && | 798 if (pRoot && pRoot->GetDict() && |
800 pRoot->GetDict()->GetElement("Pages")) { | 799 pRoot->GetDict()->GetElement("Pages")) { |
801 if (m_pTrailer) | 800 if (m_pTrailer) |
802 m_pTrailer->Release(); | 801 m_pTrailer->Release(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 --i; | 841 --i; |
843 status = 0; | 842 status = 0; |
844 break; | 843 break; |
845 } | 844 } |
846 break; | 845 break; |
847 case 7: | 846 case 7: |
848 if (inside_index == 7) { | 847 if (inside_index == 7) { |
849 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { | 848 if (PDFCharIsWhitespace(byte) || PDFCharIsDelimiter(byte)) { |
850 last_trailer = pos + i - 7; | 849 last_trailer = pos + i - 7; |
851 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); | 850 m_Syntax.RestorePos(pos + i - m_Syntax.m_HeaderOffset); |
852 CPDF_Object* pObj = | 851 CPDF_Object* pObj = m_Syntax.GetObject(m_pDocument, 0, 0, true); |
853 m_Syntax.GetObject(m_pDocument, 0, 0, nullptr, true); | |
854 if (pObj) { | 852 if (pObj) { |
855 if (!pObj->IsDictionary() && !pObj->AsStream()) { | 853 if (!pObj->IsDictionary() && !pObj->AsStream()) { |
856 pObj->Release(); | 854 pObj->Release(); |
857 } else { | 855 } else { |
858 CPDF_Stream* pStream = pObj->AsStream(); | 856 CPDF_Stream* pStream = pObj->AsStream(); |
859 if (CPDF_Dictionary* pTrailer = | 857 if (CPDF_Dictionary* pTrailer = |
860 pStream ? pStream->GetDict() : pObj->AsDictionary()) { | 858 pStream ? pStream->GetDict() : pObj->AsDictionary()) { |
861 if (m_pTrailer) { | 859 if (m_pTrailer) { |
862 CPDF_Object* pRoot = pTrailer->GetElement("Root"); | 860 CPDF_Object* pRoot = pTrailer->GetElement("Root"); |
863 CPDF_Reference* pRef = ToReference(pRoot); | 861 CPDF_Reference* pRef = ToReference(pRoot); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 void* pResult = | 989 void* pResult = |
992 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), | 990 FXSYS_bsearch(&offset, m_SortedOffset.GetData(), m_SortedOffset.GetSize(), |
993 sizeof(FX_FILESIZE), CompareFileSize); | 991 sizeof(FX_FILESIZE), CompareFileSize); |
994 if (!pResult) { | 992 if (!pResult) { |
995 m_SortedOffset.Add(offset); | 993 m_SortedOffset.Add(offset); |
996 } | 994 } |
997 return m_pTrailer && !m_ObjectInfo.empty(); | 995 return m_pTrailer && !m_ObjectInfo.empty(); |
998 } | 996 } |
999 | 997 |
1000 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { | 998 FX_BOOL CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef) { |
1001 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0, nullptr); | 999 CPDF_Object* pObject = ParseIndirectObjectAt(m_pDocument, *pos, 0); |
1002 if (!pObject) | 1000 if (!pObject) |
1003 return FALSE; | 1001 return FALSE; |
1004 if (m_pDocument) { | 1002 if (m_pDocument) { |
1005 FX_BOOL bInserted = FALSE; | 1003 FX_BOOL bInserted = FALSE; |
1006 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); | 1004 CPDF_Dictionary* pDict = m_pDocument->GetRoot(); |
1007 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { | 1005 if (!pDict || pDict->GetObjNum() != pObject->m_ObjNum) { |
1008 bInserted = m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject); | 1006 bInserted = m_pDocument->InsertIndirectObject(pObject->m_ObjNum, pObject); |
1009 } else { | 1007 } else { |
1010 if (pObject->IsStream()) | 1008 if (pObject->IsStream()) |
1011 pObject->Release(); | 1009 pObject->Release(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 m_Syntax.RestorePos(pos); | 1189 m_Syntax.RestorePos(pos); |
1192 const char kFormStream[] = "/Form\0stream"; | 1190 const char kFormStream[] = "/Form\0stream"; |
1193 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); | 1191 const CFX_ByteStringC kFormStreamStr(kFormStream, sizeof(kFormStream) - 1); |
1194 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; | 1192 bForm = m_Syntax.SearchMultiWord(kFormStreamStr, TRUE, size) == 0; |
1195 m_Syntax.RestorePos(SavedPos); | 1193 m_Syntax.RestorePos(SavedPos); |
1196 return TRUE; | 1194 return TRUE; |
1197 } | 1195 } |
1198 | 1196 |
1199 CPDF_Object* CPDF_Parser::ParseIndirectObject( | 1197 CPDF_Object* CPDF_Parser::ParseIndirectObject( |
1200 CPDF_IndirectObjectHolder* pObjList, | 1198 CPDF_IndirectObjectHolder* pObjList, |
1201 FX_DWORD objnum, | 1199 FX_DWORD objnum) { |
1202 PARSE_CONTEXT* pContext) { | |
1203 if (!IsValidObjectNumber(objnum)) | 1200 if (!IsValidObjectNumber(objnum)) |
1204 return nullptr; | 1201 return nullptr; |
1205 | 1202 |
1206 // Prevent circular parsing the same object. | 1203 // Prevent circular parsing the same object. |
1207 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) | 1204 if (pdfium::ContainsKey(m_ParsingObjNums, objnum)) |
1208 return nullptr; | 1205 return nullptr; |
1209 ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); | 1206 ScopedSetInsertion<FX_DWORD> local_insert(&m_ParsingObjNums, objnum); |
1210 | 1207 |
1211 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { | 1208 if (m_V5Type[objnum] == 1 || m_V5Type[objnum] == 255) { |
1212 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; | 1209 FX_FILESIZE pos = m_ObjectInfo[objnum].pos; |
1213 if (pos <= 0) | 1210 if (pos <= 0) |
1214 return nullptr; | 1211 return nullptr; |
1215 return ParseIndirectObjectAt(pObjList, pos, objnum, pContext); | 1212 return ParseIndirectObjectAt(pObjList, pos, objnum); |
1216 } | 1213 } |
1217 if (m_V5Type[objnum] != 2) | 1214 if (m_V5Type[objnum] != 2) |
1218 return nullptr; | 1215 return nullptr; |
1219 | 1216 |
1220 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); | 1217 CPDF_StreamAcc* pObjStream = GetObjectStream(m_ObjectInfo[objnum].pos); |
1221 if (!pObjStream) | 1218 if (!pObjStream) |
1222 return nullptr; | 1219 return nullptr; |
1223 | 1220 |
1224 ScopedFileStream file(FX_CreateMemoryStream( | 1221 ScopedFileStream file(FX_CreateMemoryStream( |
1225 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); | 1222 (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), FALSE)); |
1226 CPDF_SyntaxParser syntax; | 1223 CPDF_SyntaxParser syntax; |
1227 syntax.InitParser(file.get(), 0); | 1224 syntax.InitParser(file.get(), 0); |
1228 const int32_t offset = GetStreamFirst(pObjStream); | 1225 const int32_t offset = GetStreamFirst(pObjStream); |
1229 | 1226 |
1230 // Read object numbers from |pObjStream| into a cache. | 1227 // Read object numbers from |pObjStream| into a cache. |
1231 if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { | 1228 if (!pdfium::ContainsKey(m_ObjCache, pObjStream)) { |
1232 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { | 1229 for (int32_t i = GetStreamNCount(pObjStream); i > 0; --i) { |
1233 FX_DWORD thisnum = syntax.GetDirectNum(); | 1230 FX_DWORD thisnum = syntax.GetDirectNum(); |
1234 FX_DWORD thisoff = syntax.GetDirectNum(); | 1231 FX_DWORD thisoff = syntax.GetDirectNum(); |
1235 m_ObjCache[pObjStream][thisnum] = thisoff; | 1232 m_ObjCache[pObjStream][thisnum] = thisoff; |
1236 } | 1233 } |
1237 } | 1234 } |
1238 | 1235 |
1239 const auto it = m_ObjCache[pObjStream].find(objnum); | 1236 const auto it = m_ObjCache[pObjStream].find(objnum); |
1240 if (it == m_ObjCache[pObjStream].end()) | 1237 if (it == m_ObjCache[pObjStream].end()) |
1241 return nullptr; | 1238 return nullptr; |
1242 | 1239 |
1243 syntax.RestorePos(offset + it->second); | 1240 syntax.RestorePos(offset + it->second); |
1244 return syntax.GetObject(pObjList, 0, 0, pContext, true); | 1241 return syntax.GetObject(pObjList, 0, 0, true); |
1245 } | 1242 } |
1246 | 1243 |
1247 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { | 1244 CPDF_StreamAcc* CPDF_Parser::GetObjectStream(FX_DWORD objnum) { |
1248 auto it = m_ObjectStreamMap.find(objnum); | 1245 auto it = m_ObjectStreamMap.find(objnum); |
1249 if (it != m_ObjectStreamMap.end()) | 1246 if (it != m_ObjectStreamMap.end()) |
1250 return it->second.get(); | 1247 return it->second.get(); |
1251 | 1248 |
1252 const CPDF_Stream* pStream = ToStream( | 1249 if (!m_pDocument) |
1253 m_pDocument ? m_pDocument->GetIndirectObject(objnum, nullptr) : nullptr); | 1250 return nullptr; |
| 1251 |
| 1252 const CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(objnum)); |
1254 if (!pStream) | 1253 if (!pStream) |
1255 return nullptr; | 1254 return nullptr; |
1256 | 1255 |
1257 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; | 1256 CPDF_StreamAcc* pStreamAcc = new CPDF_StreamAcc; |
1258 pStreamAcc->LoadAllData(pStream); | 1257 pStreamAcc->LoadAllData(pStream); |
1259 m_ObjectStreamMap[objnum].reset(pStreamAcc); | 1258 m_ObjectStreamMap[objnum].reset(pStreamAcc); |
1260 return pStreamAcc; | 1259 return pStreamAcc; |
1261 } | 1260 } |
1262 | 1261 |
1263 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { | 1262 FX_FILESIZE CPDF_Parser::GetObjectSize(FX_DWORD objnum) const { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1391 size = (FX_DWORD)(nextoff - pos); | 1390 size = (FX_DWORD)(nextoff - pos); |
1392 pBuffer = FX_Alloc(uint8_t, size); | 1391 pBuffer = FX_Alloc(uint8_t, size); |
1393 m_Syntax.RestorePos(pos); | 1392 m_Syntax.RestorePos(pos); |
1394 m_Syntax.ReadBlock(pBuffer, size); | 1393 m_Syntax.ReadBlock(pBuffer, size); |
1395 m_Syntax.RestorePos(SavedPos); | 1394 m_Syntax.RestorePos(SavedPos); |
1396 } | 1395 } |
1397 | 1396 |
1398 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( | 1397 CPDF_Object* CPDF_Parser::ParseIndirectObjectAt( |
1399 CPDF_IndirectObjectHolder* pObjList, | 1398 CPDF_IndirectObjectHolder* pObjList, |
1400 FX_FILESIZE pos, | 1399 FX_FILESIZE pos, |
1401 FX_DWORD objnum, | 1400 FX_DWORD objnum) { |
1402 PARSE_CONTEXT* pContext) { | |
1403 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1401 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1404 m_Syntax.RestorePos(pos); | 1402 m_Syntax.RestorePos(pos); |
1405 bool bIsNumber; | 1403 bool bIsNumber; |
1406 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); | 1404 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1407 if (!bIsNumber) { | 1405 if (!bIsNumber) { |
1408 m_Syntax.RestorePos(SavedPos); | 1406 m_Syntax.RestorePos(SavedPos); |
1409 return NULL; | 1407 return NULL; |
1410 } | 1408 } |
1411 FX_FILESIZE objOffset = m_Syntax.SavePos(); | 1409 FX_FILESIZE objOffset = m_Syntax.SavePos(); |
1412 objOffset -= word.GetLength(); | 1410 objOffset -= word.GetLength(); |
1413 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1411 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1414 if (objnum && parser_objnum != objnum) { | 1412 if (objnum && parser_objnum != objnum) { |
1415 m_Syntax.RestorePos(SavedPos); | 1413 m_Syntax.RestorePos(SavedPos); |
1416 return NULL; | 1414 return NULL; |
1417 } | 1415 } |
1418 word = m_Syntax.GetNextWord(&bIsNumber); | 1416 word = m_Syntax.GetNextWord(&bIsNumber); |
1419 if (!bIsNumber) { | 1417 if (!bIsNumber) { |
1420 m_Syntax.RestorePos(SavedPos); | 1418 m_Syntax.RestorePos(SavedPos); |
1421 return NULL; | 1419 return NULL; |
1422 } | 1420 } |
1423 FX_DWORD parser_gennum = FXSYS_atoi(word); | 1421 FX_DWORD parser_gennum = FXSYS_atoi(word); |
1424 if (m_Syntax.GetKeyword() != "obj") { | 1422 if (m_Syntax.GetKeyword() != "obj") { |
1425 m_Syntax.RestorePos(SavedPos); | 1423 m_Syntax.RestorePos(SavedPos); |
1426 return NULL; | 1424 return NULL; |
1427 } | 1425 } |
1428 CPDF_Object* pObj = | 1426 CPDF_Object* pObj = m_Syntax.GetObject(pObjList, objnum, parser_gennum, true); |
1429 m_Syntax.GetObject(pObjList, objnum, parser_gennum, pContext, true); | |
1430 m_Syntax.SavePos(); | 1427 m_Syntax.SavePos(); |
1431 CFX_ByteString bsWord = m_Syntax.GetKeyword(); | 1428 CFX_ByteString bsWord = m_Syntax.GetKeyword(); |
1432 if (bsWord == "endobj") { | 1429 if (bsWord == "endobj") { |
1433 m_Syntax.SavePos(); | 1430 m_Syntax.SavePos(); |
1434 } | 1431 } |
1435 m_Syntax.RestorePos(SavedPos); | 1432 m_Syntax.RestorePos(SavedPos); |
1436 if (pObj) { | 1433 if (pObj) { |
1437 if (!objnum) | 1434 if (!objnum) |
1438 pObj->m_ObjNum = parser_objnum; | 1435 pObj->m_ObjNum = parser_objnum; |
1439 pObj->m_GenNum = parser_gennum; | 1436 pObj->m_GenNum = parser_gennum; |
1440 } | 1437 } |
1441 return pObj; | 1438 return pObj; |
1442 } | 1439 } |
1443 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( | 1440 CPDF_Object* CPDF_Parser::ParseIndirectObjectAtByStrict( |
1444 CPDF_IndirectObjectHolder* pObjList, | 1441 CPDF_IndirectObjectHolder* pObjList, |
1445 FX_FILESIZE pos, | 1442 FX_FILESIZE pos, |
1446 FX_DWORD objnum, | 1443 FX_DWORD objnum, |
1447 PARSE_CONTEXT* pContext, | |
1448 FX_FILESIZE* pResultPos) { | 1444 FX_FILESIZE* pResultPos) { |
1449 FX_FILESIZE SavedPos = m_Syntax.SavePos(); | 1445 FX_FILESIZE SavedPos = m_Syntax.SavePos(); |
1450 m_Syntax.RestorePos(pos); | 1446 m_Syntax.RestorePos(pos); |
1451 bool bIsNumber; | 1447 bool bIsNumber; |
1452 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); | 1448 CFX_ByteString word = m_Syntax.GetNextWord(&bIsNumber); |
1453 if (!bIsNumber) { | 1449 if (!bIsNumber) { |
1454 m_Syntax.RestorePos(SavedPos); | 1450 m_Syntax.RestorePos(SavedPos); |
1455 return NULL; | 1451 return NULL; |
1456 } | 1452 } |
1457 FX_DWORD parser_objnum = FXSYS_atoi(word); | 1453 FX_DWORD parser_objnum = FXSYS_atoi(word); |
1458 if (objnum && parser_objnum != objnum) { | 1454 if (objnum && parser_objnum != objnum) { |
1459 m_Syntax.RestorePos(SavedPos); | 1455 m_Syntax.RestorePos(SavedPos); |
1460 return NULL; | 1456 return NULL; |
1461 } | 1457 } |
1462 word = m_Syntax.GetNextWord(&bIsNumber); | 1458 word = m_Syntax.GetNextWord(&bIsNumber); |
1463 if (!bIsNumber) { | 1459 if (!bIsNumber) { |
1464 m_Syntax.RestorePos(SavedPos); | 1460 m_Syntax.RestorePos(SavedPos); |
1465 return NULL; | 1461 return NULL; |
1466 } | 1462 } |
1467 FX_DWORD gennum = FXSYS_atoi(word); | 1463 FX_DWORD gennum = FXSYS_atoi(word); |
1468 if (m_Syntax.GetKeyword() != "obj") { | 1464 if (m_Syntax.GetKeyword() != "obj") { |
1469 m_Syntax.RestorePos(SavedPos); | 1465 m_Syntax.RestorePos(SavedPos); |
1470 return NULL; | 1466 return NULL; |
1471 } | 1467 } |
1472 CPDF_Object* pObj = | 1468 CPDF_Object* pObj = m_Syntax.GetObjectByStrict(pObjList, objnum, gennum); |
1473 m_Syntax.GetObjectByStrict(pObjList, objnum, gennum, pContext); | |
1474 if (pResultPos) { | 1469 if (pResultPos) { |
1475 *pResultPos = m_Syntax.m_Pos; | 1470 *pResultPos = m_Syntax.m_Pos; |
1476 } | 1471 } |
1477 m_Syntax.RestorePos(SavedPos); | 1472 m_Syntax.RestorePos(SavedPos); |
1478 return pObj; | 1473 return pObj; |
1479 } | 1474 } |
1480 | 1475 |
1481 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { | 1476 CPDF_Dictionary* CPDF_Parser::LoadTrailerV4() { |
1482 if (m_Syntax.GetKeyword() != "trailer") | 1477 if (m_Syntax.GetKeyword() != "trailer") |
1483 return nullptr; | 1478 return nullptr; |
1484 | 1479 |
1485 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( | 1480 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( |
1486 m_Syntax.GetObject(m_pDocument, 0, 0, nullptr, true)); | 1481 m_Syntax.GetObject(m_pDocument, 0, 0, true)); |
1487 if (!ToDictionary(pObj.get())) | 1482 if (!ToDictionary(pObj.get())) |
1488 return nullptr; | 1483 return nullptr; |
1489 return pObj.release()->AsDictionary(); | 1484 return pObj.release()->AsDictionary(); |
1490 } | 1485 } |
1491 | 1486 |
1492 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { | 1487 FX_DWORD CPDF_Parser::GetPermissions(FX_BOOL bCheckRevision) { |
1493 if (!m_pSecurityHandler) { | 1488 if (!m_pSecurityHandler) { |
1494 return (FX_DWORD)-1; | 1489 return (FX_DWORD)-1; |
1495 } | 1490 } |
1496 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); | 1491 FX_DWORD dwPermission = m_pSecurityHandler->GetPermissions(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 FX_DWORD objnum = FXSYS_atoi(word); | 1524 FX_DWORD objnum = FXSYS_atoi(word); |
1530 word = m_Syntax.GetNextWord(&bIsNumber); | 1525 word = m_Syntax.GetNextWord(&bIsNumber); |
1531 if (!bIsNumber) { | 1526 if (!bIsNumber) { |
1532 return FALSE; | 1527 return FALSE; |
1533 } | 1528 } |
1534 FX_DWORD gennum = FXSYS_atoi(word); | 1529 FX_DWORD gennum = FXSYS_atoi(word); |
1535 if (m_Syntax.GetKeyword() != "obj") { | 1530 if (m_Syntax.GetKeyword() != "obj") { |
1536 m_Syntax.RestorePos(SavedPos); | 1531 m_Syntax.RestorePos(SavedPos); |
1537 return FALSE; | 1532 return FALSE; |
1538 } | 1533 } |
1539 m_pLinearized = m_Syntax.GetObject(nullptr, objnum, gennum, nullptr, true); | 1534 m_pLinearized = m_Syntax.GetObject(nullptr, objnum, gennum, true); |
1540 if (!m_pLinearized) { | 1535 if (!m_pLinearized) { |
1541 return FALSE; | 1536 return FALSE; |
1542 } | 1537 } |
1543 | 1538 |
1544 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); | 1539 CPDF_Dictionary* pDict = m_pLinearized->GetDict(); |
1545 if (pDict && pDict->GetElement("Linearized")) { | 1540 if (pDict && pDict->GetElement("Linearized")) { |
1546 m_Syntax.GetNextWord(nullptr); | 1541 m_Syntax.GetNextWord(nullptr); |
1547 | 1542 |
1548 CPDF_Object* pLen = pDict->GetElement("L"); | 1543 CPDF_Object* pLen = pDict->GetElement("L"); |
1549 if (!pLen) { | 1544 if (!pLen) { |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); | 2024 return CFX_ByteString((const FX_CHAR*)m_WordBuffer, m_WordSize); |
2030 } | 2025 } |
2031 | 2026 |
2032 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { | 2027 CFX_ByteString CPDF_SyntaxParser::GetKeyword() { |
2033 return GetNextWord(nullptr); | 2028 return GetNextWord(nullptr); |
2034 } | 2029 } |
2035 | 2030 |
2036 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, | 2031 CPDF_Object* CPDF_SyntaxParser::GetObject(CPDF_IndirectObjectHolder* pObjList, |
2037 FX_DWORD objnum, | 2032 FX_DWORD objnum, |
2038 FX_DWORD gennum, | 2033 FX_DWORD gennum, |
2039 PARSE_CONTEXT* pContext, | |
2040 FX_BOOL bDecrypt) { | 2034 FX_BOOL bDecrypt) { |
2041 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2035 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2042 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2036 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2043 return nullptr; | 2037 return nullptr; |
2044 } | 2038 } |
2045 FX_FILESIZE SavedPos = m_Pos; | 2039 FX_FILESIZE SavedPos = m_Pos; |
2046 bool bIsNumber; | 2040 bool bIsNumber; |
2047 CFX_ByteString word = GetNextWord(&bIsNumber); | 2041 CFX_ByteString word = GetNextWord(&bIsNumber); |
2048 if (word.GetLength() == 0) { | 2042 if (word.GetLength() == 0) { |
2049 return nullptr; | 2043 return nullptr; |
(...skipping 26 matching lines...) Expand all Loading... |
2076 } | 2070 } |
2077 if (word == "<") { | 2071 if (word == "<") { |
2078 CFX_ByteString str = ReadHexString(); | 2072 CFX_ByteString str = ReadHexString(); |
2079 if (m_pCryptoHandler && bDecrypt) { | 2073 if (m_pCryptoHandler && bDecrypt) { |
2080 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2074 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2081 } | 2075 } |
2082 return new CPDF_String(str, TRUE); | 2076 return new CPDF_String(str, TRUE); |
2083 } | 2077 } |
2084 if (word == "[") { | 2078 if (word == "[") { |
2085 CPDF_Array* pArray = new CPDF_Array; | 2079 CPDF_Array* pArray = new CPDF_Array; |
2086 while (CPDF_Object* pObj = | 2080 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) { |
2087 GetObject(pObjList, objnum, gennum, nullptr, true)) { | |
2088 pArray->Add(pObj); | 2081 pArray->Add(pObj); |
2089 } | 2082 } |
2090 return pArray; | 2083 return pArray; |
2091 } | 2084 } |
2092 if (word[0] == '/') { | 2085 if (word[0] == '/') { |
2093 return new CPDF_Name( | 2086 return new CPDF_Name( |
2094 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); | 2087 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); |
2095 } | 2088 } |
2096 if (word == "<<") { | 2089 if (word == "<<") { |
2097 if (pContext) | |
2098 pContext->m_DictStart = SavedPos; | |
2099 | |
2100 int32_t nKeys = 0; | 2090 int32_t nKeys = 0; |
2101 FX_FILESIZE dwSignValuePos = 0; | 2091 FX_FILESIZE dwSignValuePos = 0; |
2102 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2092 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
2103 new CPDF_Dictionary); | 2093 new CPDF_Dictionary); |
2104 while (1) { | 2094 while (1) { |
2105 CFX_ByteString key = GetNextWord(nullptr); | 2095 CFX_ByteString key = GetNextWord(nullptr); |
2106 if (key.IsEmpty()) | 2096 if (key.IsEmpty()) |
2107 return nullptr; | 2097 return nullptr; |
2108 | 2098 |
2109 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); | 2099 FX_FILESIZE SavedPos = m_Pos - key.GetLength(); |
2110 if (key == ">>") | 2100 if (key == ">>") |
2111 break; | 2101 break; |
2112 | 2102 |
2113 if (key == "endobj") { | 2103 if (key == "endobj") { |
2114 m_Pos = SavedPos; | 2104 m_Pos = SavedPos; |
2115 break; | 2105 break; |
2116 } | 2106 } |
2117 if (key[0] != '/') | 2107 if (key[0] != '/') |
2118 continue; | 2108 continue; |
2119 | 2109 |
2120 ++nKeys; | 2110 ++nKeys; |
2121 key = PDF_NameDecode(key); | 2111 key = PDF_NameDecode(key); |
2122 if (key.IsEmpty()) | 2112 if (key.IsEmpty()) |
2123 continue; | 2113 continue; |
2124 | 2114 |
2125 if (key == "/Contents") | 2115 if (key == "/Contents") |
2126 dwSignValuePos = m_Pos; | 2116 dwSignValuePos = m_Pos; |
2127 | 2117 |
2128 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, true); | 2118 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true); |
2129 if (!pObj) | 2119 if (!pObj) |
2130 continue; | 2120 continue; |
2131 | 2121 |
2132 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); | 2122 CFX_ByteStringC keyNoSlash(key.c_str() + 1, key.GetLength() - 1); |
2133 pDict->SetAt(keyNoSlash, pObj); | 2123 pDict->SetAt(keyNoSlash, pObj); |
2134 } | 2124 } |
2135 | 2125 |
2136 // Only when this is a signature dictionary and has contents, we reset the | 2126 // Only when this is a signature dictionary and has contents, we reset the |
2137 // contents to the un-decrypted form. | 2127 // contents to the un-decrypted form. |
2138 if (IsSignatureDict(pDict.get()) && dwSignValuePos) { | 2128 if (IsSignatureDict(pDict.get()) && dwSignValuePos) { |
2139 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); | 2129 CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); |
2140 m_Pos = dwSignValuePos; | 2130 m_Pos = dwSignValuePos; |
2141 CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, nullptr, FALSE); | 2131 pDict->SetAt("Contents", GetObject(pObjList, objnum, gennum, false)); |
2142 pDict->SetAt("Contents", pObj); | |
2143 } | |
2144 if (pContext) { | |
2145 pContext->m_DictEnd = m_Pos; | |
2146 } | 2132 } |
2147 FX_FILESIZE SavedPos = m_Pos; | 2133 FX_FILESIZE SavedPos = m_Pos; |
2148 CFX_ByteString nextword = GetNextWord(nullptr); | 2134 CFX_ByteString nextword = GetNextWord(nullptr); |
2149 if (nextword != "stream") { | 2135 if (nextword != "stream") { |
2150 m_Pos = SavedPos; | 2136 m_Pos = SavedPos; |
2151 return pDict.release(); | 2137 return pDict.release(); |
2152 } | 2138 } |
2153 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2139 return ReadStream(pDict.release(), objnum, gennum); |
2154 } | 2140 } |
2155 if (word == ">>") { | 2141 if (word == ">>") { |
2156 m_Pos = SavedPos; | 2142 m_Pos = SavedPos; |
2157 } | 2143 } |
2158 return nullptr; | 2144 return nullptr; |
2159 } | 2145 } |
2160 | 2146 |
2161 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( | 2147 CPDF_Object* CPDF_SyntaxParser::GetObjectByStrict( |
2162 CPDF_IndirectObjectHolder* pObjList, | 2148 CPDF_IndirectObjectHolder* pObjList, |
2163 FX_DWORD objnum, | 2149 FX_DWORD objnum, |
2164 FX_DWORD gennum, | 2150 FX_DWORD gennum) { |
2165 PARSE_CONTEXT* pContext) { | |
2166 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); | 2151 CFX_AutoRestorer<int> restorer(&s_CurrentRecursionDepth); |
2167 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { | 2152 if (++s_CurrentRecursionDepth > kParserMaxRecursionDepth) { |
2168 return nullptr; | 2153 return nullptr; |
2169 } | 2154 } |
2170 FX_FILESIZE SavedPos = m_Pos; | 2155 FX_FILESIZE SavedPos = m_Pos; |
2171 bool bIsNumber; | 2156 bool bIsNumber; |
2172 CFX_ByteString word = GetNextWord(&bIsNumber); | 2157 CFX_ByteString word = GetNextWord(&bIsNumber); |
2173 if (word.GetLength() == 0) { | 2158 if (word.GetLength() == 0) { |
2174 return nullptr; | 2159 return nullptr; |
2175 } | 2160 } |
(...skipping 23 matching lines...) Expand all Loading... |
2199 } | 2184 } |
2200 if (word == "<") { | 2185 if (word == "<") { |
2201 CFX_ByteString str = ReadHexString(); | 2186 CFX_ByteString str = ReadHexString(); |
2202 if (m_pCryptoHandler) | 2187 if (m_pCryptoHandler) |
2203 m_pCryptoHandler->Decrypt(objnum, gennum, str); | 2188 m_pCryptoHandler->Decrypt(objnum, gennum, str); |
2204 return new CPDF_String(str, TRUE); | 2189 return new CPDF_String(str, TRUE); |
2205 } | 2190 } |
2206 if (word == "[") { | 2191 if (word == "[") { |
2207 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( | 2192 std::unique_ptr<CPDF_Array, ReleaseDeleter<CPDF_Array>> pArray( |
2208 new CPDF_Array); | 2193 new CPDF_Array); |
2209 while (CPDF_Object* pObj = | 2194 while (CPDF_Object* pObj = GetObject(pObjList, objnum, gennum, true)) { |
2210 GetObject(pObjList, objnum, gennum, nullptr, true)) { | |
2211 pArray->Add(pObj); | 2195 pArray->Add(pObj); |
2212 } | 2196 } |
2213 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; | 2197 return m_WordBuffer[0] == ']' ? pArray.release() : nullptr; |
2214 } | 2198 } |
2215 if (word[0] == '/') { | 2199 if (word[0] == '/') { |
2216 return new CPDF_Name( | 2200 return new CPDF_Name( |
2217 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); | 2201 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); |
2218 } | 2202 } |
2219 if (word == "<<") { | 2203 if (word == "<<") { |
2220 if (pContext) | |
2221 pContext->m_DictStart = SavedPos; | |
2222 | |
2223 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( | 2204 std::unique_ptr<CPDF_Dictionary, ReleaseDeleter<CPDF_Dictionary>> pDict( |
2224 new CPDF_Dictionary); | 2205 new CPDF_Dictionary); |
2225 while (1) { | 2206 while (1) { |
2226 FX_FILESIZE SavedPos = m_Pos; | 2207 FX_FILESIZE SavedPos = m_Pos; |
2227 CFX_ByteString key = GetNextWord(nullptr); | 2208 CFX_ByteString key = GetNextWord(nullptr); |
2228 if (key.IsEmpty()) | 2209 if (key.IsEmpty()) |
2229 return nullptr; | 2210 return nullptr; |
2230 | 2211 |
2231 if (key == ">>") | 2212 if (key == ">>") |
2232 break; | 2213 break; |
2233 | 2214 |
2234 if (key == "endobj") { | 2215 if (key == "endobj") { |
2235 m_Pos = SavedPos; | 2216 m_Pos = SavedPos; |
2236 break; | 2217 break; |
2237 } | 2218 } |
2238 if (key[0] != '/') | 2219 if (key[0] != '/') |
2239 continue; | 2220 continue; |
2240 | 2221 |
2241 key = PDF_NameDecode(key); | 2222 key = PDF_NameDecode(key); |
2242 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( | 2223 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> obj( |
2243 GetObject(pObjList, objnum, gennum, nullptr, true)); | 2224 GetObject(pObjList, objnum, gennum, true)); |
2244 if (!obj) { | 2225 if (!obj) { |
2245 uint8_t ch; | 2226 uint8_t ch; |
2246 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { | 2227 while (GetNextChar(ch) && ch != 0x0A && ch != 0x0D) { |
2247 } | 2228 } |
2248 return nullptr; | 2229 return nullptr; |
2249 } | 2230 } |
2250 if (key.GetLength() > 1) { | 2231 if (key.GetLength() > 1) { |
2251 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), | 2232 pDict->SetAt(CFX_ByteStringC(key.c_str() + 1, key.GetLength() - 1), |
2252 obj.release()); | 2233 obj.release()); |
2253 } | 2234 } |
2254 } | 2235 } |
2255 if (pContext) { | |
2256 pContext->m_DictEnd = m_Pos; | |
2257 } | |
2258 FX_FILESIZE SavedPos = m_Pos; | 2236 FX_FILESIZE SavedPos = m_Pos; |
2259 CFX_ByteString nextword = GetNextWord(nullptr); | 2237 CFX_ByteString nextword = GetNextWord(nullptr); |
2260 if (nextword != "stream") { | 2238 if (nextword != "stream") { |
2261 m_Pos = SavedPos; | 2239 m_Pos = SavedPos; |
2262 return pDict.release(); | 2240 return pDict.release(); |
2263 } | 2241 } |
2264 | 2242 |
2265 return ReadStream(pDict.release(), pContext, objnum, gennum); | 2243 return ReadStream(pDict.release(), objnum, gennum); |
2266 } | 2244 } |
2267 if (word == ">>") { | 2245 if (word == ">>") { |
2268 m_Pos = SavedPos; | 2246 m_Pos = SavedPos; |
2269 } | 2247 } |
2270 return nullptr; | 2248 return nullptr; |
2271 } | 2249 } |
2272 | 2250 |
2273 unsigned int CPDF_SyntaxParser::ReadEOLMarkers(FX_FILESIZE pos) { | 2251 unsigned int CPDF_SyntaxParser::ReadEOLMarkers(FX_FILESIZE pos) { |
2274 unsigned char byte1 = 0; | 2252 unsigned char byte1 = 0; |
2275 unsigned char byte2 = 0; | 2253 unsigned char byte2 = 0; |
2276 GetCharAt(pos, byte1); | 2254 GetCharAt(pos, byte1); |
2277 GetCharAt(pos + 1, byte2); | 2255 GetCharAt(pos + 1, byte2); |
2278 unsigned int markers = 0; | 2256 unsigned int markers = 0; |
2279 if (byte1 == '\r' && byte2 == '\n') { | 2257 if (byte1 == '\r' && byte2 == '\n') { |
2280 markers = 2; | 2258 markers = 2; |
2281 } else if (byte1 == '\r' || byte1 == '\n') { | 2259 } else if (byte1 == '\r' || byte1 == '\n') { |
2282 markers = 1; | 2260 markers = 1; |
2283 } | 2261 } |
2284 return markers; | 2262 return markers; |
2285 } | 2263 } |
2286 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, | 2264 CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, |
2287 PARSE_CONTEXT* pContext, | |
2288 FX_DWORD objnum, | 2265 FX_DWORD objnum, |
2289 FX_DWORD gennum) { | 2266 FX_DWORD gennum) { |
2290 CPDF_Object* pLenObj = pDict->GetElement("Length"); | 2267 CPDF_Object* pLenObj = pDict->GetElement("Length"); |
2291 FX_FILESIZE len = -1; | 2268 FX_FILESIZE len = -1; |
2292 CPDF_Reference* pLenObjRef = ToReference(pLenObj); | 2269 CPDF_Reference* pLenObjRef = ToReference(pLenObj); |
2293 | 2270 |
2294 bool differingObjNum = !pLenObjRef || (pLenObjRef->GetObjList() && | 2271 bool differingObjNum = !pLenObjRef || (pLenObjRef->GetObjList() && |
2295 pLenObjRef->GetRefObjNum() != objnum); | 2272 pLenObjRef->GetRefObjNum() != objnum); |
2296 if (pLenObj && differingObjNum) | 2273 if (pLenObj && differingObjNum) |
2297 len = pLenObj->GetInteger(); | 2274 len = pLenObj->GetInteger(); |
2298 | 2275 |
2299 // Locate the start of stream. | 2276 // Locate the start of stream. |
2300 ToNextLine(); | 2277 ToNextLine(); |
2301 FX_FILESIZE streamStartPos = m_Pos; | 2278 FX_FILESIZE streamStartPos = m_Pos; |
2302 if (pContext) { | |
2303 pContext->m_DataStart = streamStartPos; | |
2304 } | |
2305 | |
2306 const CFX_ByteStringC kEndStreamStr("endstream"); | 2279 const CFX_ByteStringC kEndStreamStr("endstream"); |
2307 const CFX_ByteStringC kEndObjStr("endobj"); | 2280 const CFX_ByteStringC kEndObjStr("endobj"); |
2308 CPDF_CryptoHandler* pCryptoHandler = | 2281 CPDF_CryptoHandler* pCryptoHandler = |
2309 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); | 2282 objnum == (FX_DWORD)m_MetadataObjnum ? nullptr : m_pCryptoHandler.get(); |
2310 if (!pCryptoHandler) { | 2283 if (!pCryptoHandler) { |
2311 FX_BOOL bSearchForKeyword = TRUE; | 2284 FX_BOOL bSearchForKeyword = TRUE; |
2312 if (len >= 0) { | 2285 if (len >= 0) { |
2313 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; | 2286 pdfium::base::CheckedNumeric<FX_FILESIZE> pos = m_Pos; |
2314 pos += len; | 2287 pos += len; |
2315 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { | 2288 if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2405 void* context = pCryptoHandler->DecryptStart(objnum, gennum); | 2378 void* context = pCryptoHandler->DecryptStart(objnum, gennum); |
2406 pCryptoHandler->DecryptStream(context, pData, len, dest_buf); | 2379 pCryptoHandler->DecryptStream(context, pData, len, dest_buf); |
2407 pCryptoHandler->DecryptFinish(context, dest_buf); | 2380 pCryptoHandler->DecryptFinish(context, dest_buf); |
2408 FX_Free(pData); | 2381 FX_Free(pData); |
2409 pData = dest_buf.GetBuffer(); | 2382 pData = dest_buf.GetBuffer(); |
2410 len = dest_buf.GetSize(); | 2383 len = dest_buf.GetSize(); |
2411 dest_buf.DetachBuffer(); | 2384 dest_buf.DetachBuffer(); |
2412 } | 2385 } |
2413 } | 2386 } |
2414 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); | 2387 CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict); |
2415 if (pContext) { | |
2416 pContext->m_DataEnd = pContext->m_DataStart + len; | |
2417 } | |
2418 streamStartPos = m_Pos; | 2388 streamStartPos = m_Pos; |
2419 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); | 2389 FXSYS_memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1); |
2420 GetNextWordInternal(nullptr); | 2390 GetNextWordInternal(nullptr); |
2421 int numMarkers = ReadEOLMarkers(m_Pos); | 2391 int numMarkers = ReadEOLMarkers(m_Pos); |
2422 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && | 2392 if (m_WordSize == kEndObjStr.GetLength() && numMarkers != 0 && |
2423 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == | 2393 FXSYS_memcmp(m_WordBuffer, kEndObjStr.GetPtr(), kEndObjStr.GetLength()) == |
2424 0) { | 2394 0) { |
2425 m_Pos = streamStartPos; | 2395 m_Pos = streamStartPos; |
2426 } | 2396 } |
2427 return pStream; | 2397 return pStream; |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3001 FX_DWORD size = GetObjectSize(dwNum, offset); | 2971 FX_DWORD size = GetObjectSize(dwNum, offset); |
3002 if (size == 0 || offset < 0 || offset >= m_dwFileLen) { | 2972 if (size == 0 || offset < 0 || offset >= m_dwFileLen) { |
3003 break; | 2973 break; |
3004 } | 2974 } |
3005 if (!IsDataAvail(offset, size, pHints)) { | 2975 if (!IsDataAvail(offset, size, pHints)) { |
3006 ret_array.Add(pObj); | 2976 ret_array.Add(pObj); |
3007 count++; | 2977 count++; |
3008 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { | 2978 } else if (!pdfium::ContainsKey(m_ObjectSet, dwNum)) { |
3009 m_ObjectSet.insert(dwNum); | 2979 m_ObjectSet.insert(dwNum); |
3010 CPDF_Object* pReferred = | 2980 CPDF_Object* pReferred = |
3011 m_pDocument->GetIndirectObject(pRef->GetRefObjNum(), nullptr); | 2981 m_pDocument->GetIndirectObject(pRef->GetRefObjNum()); |
3012 if (pReferred) { | 2982 if (pReferred) { |
3013 new_obj_array.Add(pReferred); | 2983 new_obj_array.Add(pReferred); |
3014 } | 2984 } |
3015 } | 2985 } |
3016 } break; | 2986 } break; |
3017 } | 2987 } |
3018 } | 2988 } |
3019 if (count > 0) { | 2989 if (count > 0) { |
3020 int32_t iSize = new_obj_array.GetSize(); | 2990 int32_t iSize = new_obj_array.GetSize(); |
3021 for (i = 0; i < iSize; ++i) { | 2991 for (i = 0; i < iSize; ++i) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3200 pParser = (CPDF_Parser*)(m_pDocument->GetParser()); | 3170 pParser = (CPDF_Parser*)(m_pDocument->GetParser()); |
3201 } else { | 3171 } else { |
3202 size = (FX_DWORD)m_parser.GetObjectSize(objnum); | 3172 size = (FX_DWORD)m_parser.GetObjectSize(objnum); |
3203 offset = m_parser.GetObjectOffset(objnum); | 3173 offset = m_parser.GetObjectOffset(objnum); |
3204 pParser = &m_parser; | 3174 pParser = &m_parser; |
3205 } | 3175 } |
3206 if (!IsDataAvail(offset, size, pHints)) { | 3176 if (!IsDataAvail(offset, size, pHints)) { |
3207 return nullptr; | 3177 return nullptr; |
3208 } | 3178 } |
3209 if (pParser) { | 3179 if (pParser) { |
3210 pRet = pParser->ParseIndirectObject(NULL, objnum, NULL); | 3180 pRet = pParser->ParseIndirectObject(nullptr, objnum); |
3211 } | 3181 } |
3212 | |
3213 if (!pRet && pExistInFile) { | 3182 if (!pRet && pExistInFile) { |
3214 *pExistInFile = FALSE; | 3183 *pExistInFile = FALSE; |
3215 } | 3184 } |
3216 | |
3217 return pRet; | 3185 return pRet; |
3218 } | 3186 } |
3219 | 3187 |
3220 FX_BOOL CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) { | 3188 FX_BOOL CPDF_DataAvail::CheckInfo(IFX_DownloadHints* pHints) { |
3221 FX_BOOL bExist = FALSE; | 3189 FX_BOOL bExist = FALSE; |
3222 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); | 3190 CPDF_Object* pInfo = GetObject(m_dwInfoObjNum, pHints, &bExist); |
3223 if (!bExist) { | 3191 if (!bExist) { |
3224 if (m_bHaveAcroForm) { | 3192 if (m_bHaveAcroForm) { |
3225 m_docStatus = PDF_DATAAVAIL_ACROFORM; | 3193 m_docStatus = PDF_DATAAVAIL_ACROFORM; |
3226 } else { | 3194 } else { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3583 word = m_syntaxParser.GetNextWord(&bIsNumber); | 3551 word = m_syntaxParser.GetNextWord(&bIsNumber); |
3584 if (!bIsNumber) | 3552 if (!bIsNumber) |
3585 return nullptr; | 3553 return nullptr; |
3586 | 3554 |
3587 FX_DWORD gennum = FXSYS_atoi(word); | 3555 FX_DWORD gennum = FXSYS_atoi(word); |
3588 if (m_syntaxParser.GetKeyword() != "obj") { | 3556 if (m_syntaxParser.GetKeyword() != "obj") { |
3589 m_syntaxParser.RestorePos(SavedPos); | 3557 m_syntaxParser.RestorePos(SavedPos); |
3590 return nullptr; | 3558 return nullptr; |
3591 } | 3559 } |
3592 CPDF_Object* pObj = | 3560 CPDF_Object* pObj = |
3593 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, nullptr, true); | 3561 m_syntaxParser.GetObject(pObjList, parser_objnum, gennum, true); |
3594 m_syntaxParser.RestorePos(SavedPos); | 3562 m_syntaxParser.RestorePos(SavedPos); |
3595 return pObj; | 3563 return pObj; |
3596 } | 3564 } |
3597 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { | 3565 IPDF_DataAvail::DocLinearizationStatus CPDF_DataAvail::IsLinearizedPDF() { |
3598 FX_DWORD req_size = 1024; | 3566 FX_DWORD req_size = 1024; |
3599 if (!m_pFileAvail->IsDataAvail(0, req_size)) { | 3567 if (!m_pFileAvail->IsDataAvail(0, req_size)) { |
3600 return LinearizationUnknown; | 3568 return LinearizationUnknown; |
3601 } | 3569 } |
3602 if (!m_pFileRead) { | 3570 if (!m_pFileRead) { |
3603 return NotLinearized; | 3571 return NotLinearized; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3701 uint8_t* pBuf = buf.GetBuffer(); | 3669 uint8_t* pBuf = buf.GetBuffer(); |
3702 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); | 3670 m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize); |
3703 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 3671 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
3704 m_parser.m_Syntax.InitParser(file.get(), 0); | 3672 m_parser.m_Syntax.InitParser(file.get(), 0); |
3705 bool bNumber; | 3673 bool bNumber; |
3706 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(&bNumber); | 3674 CFX_ByteString objnum = m_parser.m_Syntax.GetNextWord(&bNumber); |
3707 if (!bNumber) | 3675 if (!bNumber) |
3708 return -1; | 3676 return -1; |
3709 | 3677 |
3710 FX_DWORD objNum = FXSYS_atoi(objnum); | 3678 FX_DWORD objNum = FXSYS_atoi(objnum); |
3711 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(NULL, 0, objNum, NULL); | 3679 CPDF_Object* pObj = m_parser.ParseIndirectObjectAt(nullptr, 0, objNum); |
3712 if (!pObj) { | 3680 if (!pObj) { |
3713 m_Pos += m_parser.m_Syntax.SavePos(); | 3681 m_Pos += m_parser.m_Syntax.SavePos(); |
3714 return 0; | 3682 return 0; |
3715 } | 3683 } |
3716 CPDF_Dictionary* pDict = pObj->GetDict(); | 3684 CPDF_Dictionary* pDict = pObj->GetDict(); |
3717 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); | 3685 CPDF_Name* pName = ToName(pDict ? pDict->GetElement("Type") : nullptr); |
3718 if (pName) { | 3686 if (pName) { |
3719 if (pName->GetString() == "XRef") { | 3687 if (pName->GetString() == "XRef") { |
3720 m_Pos += m_parser.m_Syntax.SavePos(); | 3688 m_Pos += m_parser.m_Syntax.SavePos(); |
3721 xref_offset = pObj->GetDict()->GetInteger("Prev"); | 3689 xref_offset = pObj->GetDict()->GetInteger("Prev"); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3931 if (!pBuf) { | 3899 if (!pBuf) { |
3932 m_docStatus = PDF_DATAAVAIL_ERROR; | 3900 m_docStatus = PDF_DATAAVAIL_ERROR; |
3933 return FALSE; | 3901 return FALSE; |
3934 } | 3902 } |
3935 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { | 3903 if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize)) { |
3936 return FALSE; | 3904 return FALSE; |
3937 } | 3905 } |
3938 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); | 3906 ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, FALSE)); |
3939 m_syntaxParser.InitParser(file.get(), 0); | 3907 m_syntaxParser.InitParser(file.get(), 0); |
3940 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( | 3908 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pTrailer( |
3941 m_syntaxParser.GetObject(nullptr, 0, 0, nullptr, true)); | 3909 m_syntaxParser.GetObject(nullptr, 0, 0, true)); |
3942 if (!pTrailer) { | 3910 if (!pTrailer) { |
3943 m_Pos += m_syntaxParser.SavePos(); | 3911 m_Pos += m_syntaxParser.SavePos(); |
3944 pHints->AddSegment(m_Pos, iTrailerSize); | 3912 pHints->AddSegment(m_Pos, iTrailerSize); |
3945 return FALSE; | 3913 return FALSE; |
3946 } | 3914 } |
3947 if (!pTrailer->IsDictionary()) | 3915 if (!pTrailer->IsDictionary()) |
3948 return FALSE; | 3916 return FALSE; |
3949 | 3917 |
3950 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); | 3918 CPDF_Dictionary* pTrailerDict = pTrailer->GetDict(); |
3951 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); | 3919 CPDF_Object* pEncrypt = pTrailerDict->GetElement("Encrypt"); |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4922 if (!m_pLinearizedDict) | 4890 if (!m_pLinearizedDict) |
4923 return -1; | 4891 return -1; |
4924 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); | 4892 CPDF_Array* pRange = m_pLinearizedDict->GetArray("H"); |
4925 if (!pRange) | 4893 if (!pRange) |
4926 return -1; | 4894 return -1; |
4927 CPDF_Object* pStreamLen = pRange->GetElementValue(1); | 4895 CPDF_Object* pStreamLen = pRange->GetElementValue(1); |
4928 if (!pStreamLen) | 4896 if (!pStreamLen) |
4929 return -1; | 4897 return -1; |
4930 return pStreamLen->GetInteger(); | 4898 return pStreamLen->GetInteger(); |
4931 } | 4899 } |
OLD | NEW |