| 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 "editint.h" | 7 #include "core/src/fpdfapi/fpdf_edit/editint.h" |
| 8 |
| 9 #include <vector> |
| 8 | 10 |
| 9 #include "core/include/fxcrt/fx_ext.h" | 11 #include "core/include/fxcrt/fx_ext.h" |
| 10 #include "core/include/fpdfapi/fpdf_serial.h" | 12 #include "core/include/fpdfapi/fpdf_serial.h" |
| 11 #include "core/include/fpdfapi/fpdf_parser.h" | 13 #include "core/include/fpdfapi/fpdf_parser.h" |
| 12 | 14 |
| 13 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) | 15 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) |
| 14 #define PDF_XREFSTREAM_MAXSIZE 10000 | 16 #define PDF_XREFSTREAM_MAXSIZE 10000 |
| 15 | 17 |
| 18 namespace { |
| 19 |
| 16 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, | 20 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, |
| 17 CFX_FileBufferArchive* pFile, | 21 CFX_FileBufferArchive* pFile, |
| 18 FX_FILESIZE& offset) { | 22 FX_FILESIZE& offset) { |
| 19 int32_t len = 0; | 23 int32_t len = 0; |
| 20 if (!pObj) { | 24 if (!pObj) { |
| 21 if (pFile->AppendString(" null") < 0) { | 25 if (pFile->AppendString(" null") < 0) { |
| 22 return -1; | 26 return -1; |
| 23 } | 27 } |
| 24 offset += 5; | 28 offset += 5; |
| 25 return 1; | 29 return 1; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 166 } |
| 163 offset += len; | 167 offset += len; |
| 164 break; | 168 break; |
| 165 } | 169 } |
| 166 default: | 170 default: |
| 167 ASSERT(FALSE); | 171 ASSERT(FALSE); |
| 168 break; | 172 break; |
| 169 } | 173 } |
| 170 return 1; | 174 return 1; |
| 171 } | 175 } |
| 176 |
| 172 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, | 177 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, |
| 173 CFX_FileBufferArchive* pFile, | 178 CFX_FileBufferArchive* pFile, |
| 174 CPDF_Array* pIDArray, | 179 CPDF_Array* pIDArray, |
| 175 FX_BOOL bCompress) { | 180 FX_BOOL bCompress) { |
| 176 FX_FILESIZE offset = 0; | 181 FX_FILESIZE offset = 0; |
| 177 int32_t len = 0; | 182 int32_t len = 0; |
| 178 FXSYS_assert(pDocument && pFile); | 183 FXSYS_assert(pDocument && pFile); |
| 179 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); | 184 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); |
| 180 if (pParser) { | 185 if (pParser) { |
| 181 CPDF_Dictionary* p = pParser->GetTrailer(); | 186 CPDF_Dictionary* p = pParser->GetTrailer(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (pFile->AppendString(("/ID")) < 0) { | 257 if (pFile->AppendString(("/ID")) < 0) { |
| 253 return -1; | 258 return -1; |
| 254 } | 259 } |
| 255 offset += 3; | 260 offset += 3; |
| 256 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { | 261 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { |
| 257 return -1; | 262 return -1; |
| 258 } | 263 } |
| 259 } | 264 } |
| 260 return offset; | 265 return offset; |
| 261 } | 266 } |
| 267 |
| 262 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, | 268 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, |
| 263 FX_DWORD dwObjNum, | 269 FX_DWORD dwObjNum, |
| 264 CFX_FileBufferArchive* pFile) { | 270 CFX_FileBufferArchive* pFile) { |
| 265 if (!pEncryptDict) { | 271 if (!pEncryptDict) { |
| 266 return 0; | 272 return 0; |
| 267 } | 273 } |
| 268 FXSYS_assert(pFile); | 274 FXSYS_assert(pFile); |
| 269 FX_FILESIZE offset = 0; | 275 FX_FILESIZE offset = 0; |
| 270 int32_t len = 0; | 276 int32_t len = 0; |
| 271 if (pFile->AppendString("/Encrypt") < 0) { | 277 if (pFile->AppendString("/Encrypt") < 0) { |
| 272 return -1; | 278 return -1; |
| 273 } | 279 } |
| 274 offset += 8; | 280 offset += 8; |
| 275 if (pFile->AppendString(" ") < 0) { | 281 if (pFile->AppendString(" ") < 0) { |
| 276 return -1; | 282 return -1; |
| 277 } | 283 } |
| 278 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { | 284 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { |
| 279 return -1; | 285 return -1; |
| 280 } | 286 } |
| 281 if (pFile->AppendString(" 0 R ") < 0) { | 287 if (pFile->AppendString(" 0 R ") < 0) { |
| 282 return -1; | 288 return -1; |
| 283 } | 289 } |
| 284 offset += len + 6; | 290 offset += len + 6; |
| 285 return offset; | 291 return offset; |
| 286 } | 292 } |
| 287 FX_BOOL PDF_GenerateFileID(FX_DWORD dwSeed1, | 293 |
| 288 FX_DWORD dwSeed2, | 294 std::vector<uint8_t> PDF_GenerateFileID(FX_DWORD dwSeed1, FX_DWORD dwSeed2) { |
| 289 FX_DWORD* pBuffer) { | 295 std::vector<uint8_t> buffer(sizeof(FX_DWORD) * 4); |
| 290 if (!pBuffer) { | 296 FX_DWORD* pBuffer = reinterpret_cast<FX_DWORD*>(buffer.data()); |
| 291 return FALSE; | |
| 292 } | |
| 293 void* pContext = FX_Random_MT_Start(dwSeed1); | 297 void* pContext = FX_Random_MT_Start(dwSeed1); |
| 294 int32_t i = 0; | 298 for (int i = 0; i < 2; ++i) |
| 295 for (i = 0; i < 2; i++) { | |
| 296 *pBuffer++ = FX_Random_MT_Generate(pContext); | 299 *pBuffer++ = FX_Random_MT_Generate(pContext); |
| 297 } | |
| 298 FX_Random_MT_Close(pContext); | 300 FX_Random_MT_Close(pContext); |
| 299 pContext = FX_Random_MT_Start(dwSeed2); | 301 pContext = FX_Random_MT_Start(dwSeed2); |
| 300 for (i = 0; i < 2; i++) { | 302 for (int i = 0; i < 2; ++i) |
| 301 *pBuffer++ = FX_Random_MT_Generate(pContext); | 303 *pBuffer++ = FX_Random_MT_Generate(pContext); |
| 304 FX_Random_MT_Close(pContext); |
| 305 return buffer; |
| 306 } |
| 307 |
| 308 void AppendIndex0(CFX_ByteTextBuf& buffer, bool bFirstObject) { |
| 309 buffer.AppendByte(0); |
| 310 buffer.AppendByte(0); |
| 311 buffer.AppendByte(0); |
| 312 buffer.AppendByte(0); |
| 313 buffer.AppendByte(0); |
| 314 const uint8_t byte = bFirstObject ? 0xFF : 0; |
| 315 buffer.AppendByte(byte); |
| 316 buffer.AppendByte(byte); |
| 317 } |
| 318 |
| 319 void AppendIndex1(CFX_ByteTextBuf& buffer, FX_FILESIZE offset) { |
| 320 buffer.AppendByte(1); |
| 321 buffer.AppendByte(FX_GETBYTEOFFSET24(offset)); |
| 322 buffer.AppendByte(FX_GETBYTEOFFSET16(offset)); |
| 323 buffer.AppendByte(FX_GETBYTEOFFSET8(offset)); |
| 324 buffer.AppendByte(FX_GETBYTEOFFSET0(offset)); |
| 325 buffer.AppendByte(0); |
| 326 buffer.AppendByte(0); |
| 327 } |
| 328 |
| 329 void AppendIndex2(CFX_ByteTextBuf& buffer, FX_DWORD objnum, int32_t index) { |
| 330 buffer.AppendByte(2); |
| 331 buffer.AppendByte(FX_GETBYTEOFFSET24(objnum)); |
| 332 buffer.AppendByte(FX_GETBYTEOFFSET16(objnum)); |
| 333 buffer.AppendByte(FX_GETBYTEOFFSET8(objnum)); |
| 334 buffer.AppendByte(FX_GETBYTEOFFSET0(objnum)); |
| 335 buffer.AppendByte(FX_GETBYTEOFFSET8(index)); |
| 336 buffer.AppendByte(FX_GETBYTEOFFSET0(index)); |
| 337 } |
| 338 |
| 339 bool IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) { |
| 340 if (!(flag & FPDFCREATE_INCREMENTAL)) |
| 341 return false; |
| 342 |
| 343 int32_t iSize = pXRef->m_IndexArray.GetSize() / 2; |
| 344 int32_t iCount = 0; |
| 345 for (int32_t i = 0; i < iSize; ++i) |
| 346 iCount += pXRef->m_IndexArray.ElementAt(i * 2 + 1); |
| 347 return iCount >= PDF_XREFSTREAM_MAXSIZE; |
| 348 } |
| 349 |
| 350 int32_t OutputIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { |
| 351 if (sizeof(offset) > 4) { |
| 352 if (FX_GETBYTEOFFSET32(offset)) { |
| 353 if (pFile->AppendByte(FX_GETBYTEOFFSET56(offset)) < 0) |
| 354 return -1; |
| 355 if (pFile->AppendByte(FX_GETBYTEOFFSET48(offset)) < 0) |
| 356 return -1; |
| 357 if (pFile->AppendByte(FX_GETBYTEOFFSET40(offset)) < 0) |
| 358 return -1; |
| 359 if (pFile->AppendByte(FX_GETBYTEOFFSET32(offset)) < 0) |
| 360 return -1; |
| 361 } |
| 302 } | 362 } |
| 303 FX_Random_MT_Close(pContext); | 363 if (pFile->AppendByte(FX_GETBYTEOFFSET24(offset)) < 0) |
| 304 return TRUE; | 364 return -1; |
| 365 if (pFile->AppendByte(FX_GETBYTEOFFSET16(offset)) < 0) |
| 366 return -1; |
| 367 if (pFile->AppendByte(FX_GETBYTEOFFSET8(offset)) < 0) |
| 368 return -1; |
| 369 if (pFile->AppendByte(FX_GETBYTEOFFSET0(offset)) < 0) |
| 370 return -1; |
| 371 if (pFile->AppendByte(0) < 0) |
| 372 return -1; |
| 373 return 0; |
| 305 } | 374 } |
| 375 |
| 306 class CPDF_FlateEncoder { | 376 class CPDF_FlateEncoder { |
| 307 public: | 377 public: |
| 308 CPDF_FlateEncoder(); | 378 CPDF_FlateEncoder(); |
| 309 ~CPDF_FlateEncoder(); | 379 ~CPDF_FlateEncoder(); |
| 310 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); | 380 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); |
| 311 FX_BOOL Initialize(const uint8_t* pBuffer, | 381 FX_BOOL Initialize(const uint8_t* pBuffer, |
| 312 FX_DWORD size, | 382 FX_DWORD size, |
| 313 FX_BOOL bFlateEncode, | 383 FX_BOOL bFlateEncode, |
| 314 FX_BOOL bXRefStream = FALSE); | 384 FX_BOOL bXRefStream = FALSE); |
| 315 void CloneDict(); | 385 void CloneDict(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 m_pData = FX_Alloc(uint8_t, m_dwSize); | 496 m_pData = FX_Alloc(uint8_t, m_dwSize); |
| 427 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); | 497 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); |
| 428 m_bNewBuf = TRUE; | 498 m_bNewBuf = TRUE; |
| 429 return TRUE; | 499 return TRUE; |
| 430 } | 500 } |
| 431 CPDF_Encryptor::~CPDF_Encryptor() { | 501 CPDF_Encryptor::~CPDF_Encryptor() { |
| 432 if (m_bNewBuf) { | 502 if (m_bNewBuf) { |
| 433 FX_Free(m_pData); | 503 FX_Free(m_pData); |
| 434 } | 504 } |
| 435 } | 505 } |
| 506 |
| 507 } // namespace |
| 508 |
| 436 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} | 509 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} |
| 437 FX_BOOL CPDF_ObjectStream::Start() { | 510 FX_BOOL CPDF_ObjectStream::Start() { |
| 438 m_ObjNumArray.RemoveAll(); | 511 m_ObjNumArray.RemoveAll(); |
| 439 m_OffsetArray.RemoveAll(); | 512 m_OffsetArray.RemoveAll(); |
| 440 m_Buffer.Clear(); | 513 m_Buffer.Clear(); |
| 441 m_dwObjNum = 0; | 514 m_dwObjNum = 0; |
| 442 m_index = 0; | 515 m_index = 0; |
| 443 return TRUE; | 516 return TRUE; |
| 444 } | 517 } |
| 445 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, | 518 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 if (!pCreator) { | 648 if (!pCreator) { |
| 576 return 0; | 649 return 0; |
| 577 } | 650 } |
| 578 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); | 651 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); |
| 579 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && | 652 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && |
| 580 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { | 653 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { |
| 581 return 1; | 654 return 1; |
| 582 } | 655 } |
| 583 return EndObjectStream(pCreator); | 656 return EndObjectStream(pCreator); |
| 584 } | 657 } |
| 585 static void _AppendIndex0(CFX_ByteTextBuf& buffer, | 658 |
| 586 FX_BOOL bFirstObject = TRUE) { | |
| 587 buffer.AppendByte(0); | |
| 588 buffer.AppendByte(0); | |
| 589 buffer.AppendByte(0); | |
| 590 buffer.AppendByte(0); | |
| 591 buffer.AppendByte(0); | |
| 592 if (bFirstObject) { | |
| 593 buffer.AppendByte(0xFF); | |
| 594 buffer.AppendByte(0xFF); | |
| 595 } else { | |
| 596 buffer.AppendByte(0); | |
| 597 buffer.AppendByte(0); | |
| 598 } | |
| 599 } | |
| 600 static void _AppendIndex1(CFX_ByteTextBuf& buffer, FX_FILESIZE offset) { | |
| 601 buffer.AppendByte(1); | |
| 602 buffer.AppendByte(FX_GETBYTEOFFSET24(offset)); | |
| 603 buffer.AppendByte(FX_GETBYTEOFFSET16(offset)); | |
| 604 buffer.AppendByte(FX_GETBYTEOFFSET8(offset)); | |
| 605 buffer.AppendByte(FX_GETBYTEOFFSET0(offset)); | |
| 606 buffer.AppendByte(0); | |
| 607 buffer.AppendByte(0); | |
| 608 } | |
| 609 static void _AppendIndex2(CFX_ByteTextBuf& buffer, | |
| 610 FX_DWORD objnum, | |
| 611 int32_t index) { | |
| 612 buffer.AppendByte(2); | |
| 613 buffer.AppendByte(FX_GETBYTEOFFSET24(objnum)); | |
| 614 buffer.AppendByte(FX_GETBYTEOFFSET16(objnum)); | |
| 615 buffer.AppendByte(FX_GETBYTEOFFSET8(objnum)); | |
| 616 buffer.AppendByte(FX_GETBYTEOFFSET0(objnum)); | |
| 617 buffer.AppendByte(FX_GETBYTEOFFSET8(index)); | |
| 618 buffer.AppendByte(FX_GETBYTEOFFSET0(index)); | |
| 619 } | |
| 620 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { | 659 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 621 FX_FILESIZE objOffset = 0; | 660 FX_FILESIZE objOffset = 0; |
| 622 if (bEOF) { | 661 if (bEOF) { |
| 623 objOffset = m_ObjStream.End(pCreator); | 662 objOffset = m_ObjStream.End(pCreator); |
| 624 if (objOffset < 0) { | 663 if (objOffset < 0) { |
| 625 return -1; | 664 return -1; |
| 626 } | 665 } |
| 627 } | 666 } |
| 628 FX_DWORD& dwObjStmNum = m_ObjStream.m_dwObjNum; | 667 FX_DWORD& dwObjStmNum = m_ObjStream.m_dwObjNum; |
| 629 if (!dwObjStmNum) { | 668 if (!dwObjStmNum) { |
| 630 dwObjStmNum = ++pCreator->m_dwLastObjNum; | 669 dwObjStmNum = ++pCreator->m_dwLastObjNum; |
| 631 } | 670 } |
| 632 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); | 671 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); |
| 633 int32_t iSeg = m_IndexArray.GetSize() / 2; | 672 int32_t iSeg = m_IndexArray.GetSize() / 2; |
| 634 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 673 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 635 if (m_dwTempObjNum == 0) { | 674 if (m_dwTempObjNum == 0) { |
| 636 _AppendIndex0(m_Buffer); | 675 AppendIndex0(m_Buffer, true); |
| 637 m_dwTempObjNum++; | 676 m_dwTempObjNum++; |
| 638 } | 677 } |
| 639 FX_DWORD end_num = m_IndexArray.GetAt((iSeg - 1) * 2) + | 678 FX_DWORD end_num = m_IndexArray.GetAt((iSeg - 1) * 2) + |
| 640 m_IndexArray.GetAt((iSeg - 1) * 2 + 1); | 679 m_IndexArray.GetAt((iSeg - 1) * 2 + 1); |
| 641 int index = 0; | 680 int index = 0; |
| 642 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { | 681 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { |
| 643 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 682 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 644 if (offset) { | 683 if (offset) { |
| 645 if (index >= iSize || | 684 if (index >= iSize || |
| 646 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { | 685 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { |
| 647 _AppendIndex1(m_Buffer, *offset); | 686 AppendIndex1(m_Buffer, *offset); |
| 648 } else { | 687 } else { |
| 649 _AppendIndex2(m_Buffer, dwObjStmNum, index++); | 688 AppendIndex2(m_Buffer, dwObjStmNum, index++); |
| 650 } | 689 } |
| 651 } else { | 690 } else { |
| 652 _AppendIndex0(m_Buffer, FALSE); | 691 AppendIndex0(m_Buffer, false); |
| 653 } | 692 } |
| 654 } | 693 } |
| 655 if (iSize > 0 && bEOF) { | 694 if (iSize > 0 && bEOF) { |
| 656 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); | 695 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); |
| 657 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; | 696 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; |
| 658 } | 697 } |
| 659 m_iSeg = iSeg; | 698 m_iSeg = iSeg; |
| 660 if (bEOF) { | 699 if (bEOF) { |
| 661 m_ObjStream.Start(); | 700 m_ObjStream.Start(); |
| 662 } | 701 } |
| 663 return 1; | 702 return 1; |
| 664 } | 703 } |
| 665 int32_t& j = m_ObjStream.m_index; | 704 int32_t& j = m_ObjStream.m_index; |
| 666 for (int i = m_iSeg; i < iSeg; i++) { | 705 for (int i = m_iSeg; i < iSeg; i++) { |
| 667 FX_DWORD start = m_IndexArray.ElementAt(i * 2); | 706 FX_DWORD start = m_IndexArray.ElementAt(i * 2); |
| 668 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; | 707 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; |
| 669 for (FX_DWORD m = start; m < end; m++) { | 708 for (FX_DWORD m = start; m < end; m++) { |
| 670 if (j >= iSize || m != m_ObjStream.m_ObjNumArray.ElementAt(j)) { | 709 if (j >= iSize || m != m_ObjStream.m_ObjNumArray.ElementAt(j)) { |
| 671 _AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); | 710 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); |
| 672 } else { | 711 } else { |
| 673 _AppendIndex2(m_Buffer, dwObjStmNum, j++); | 712 AppendIndex2(m_Buffer, dwObjStmNum, j++); |
| 674 } | 713 } |
| 675 } | 714 } |
| 676 } | 715 } |
| 677 if (iSize > 0 && bEOF) { | 716 if (iSize > 0 && bEOF) { |
| 678 _AppendIndex1(m_Buffer, objOffset); | 717 AppendIndex1(m_Buffer, objOffset); |
| 679 m_IndexArray.Add(dwObjStmNum); | 718 m_IndexArray.Add(dwObjStmNum); |
| 680 m_IndexArray.Add(1); | 719 m_IndexArray.Add(1); |
| 681 iSeg += 1; | 720 iSeg += 1; |
| 682 } | 721 } |
| 683 m_iSeg = iSeg; | 722 m_iSeg = iSeg; |
| 684 if (bEOF) { | 723 if (bEOF) { |
| 685 m_ObjStream.Start(); | 724 m_ObjStream.Start(); |
| 686 } | 725 } |
| 687 return 1; | 726 return 1; |
| 688 } | 727 } |
| 689 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, | 728 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, |
| 690 FX_BOOL bEOF) { | 729 FX_BOOL bEOF) { |
| 691 FX_FILESIZE offset_tmp = pCreator->m_Offset; | 730 FX_FILESIZE offset_tmp = pCreator->m_Offset; |
| 692 FX_DWORD objnum = ++pCreator->m_dwLastObjNum; | 731 FX_DWORD objnum = ++pCreator->m_dwLastObjNum; |
| 693 CFX_FileBufferArchive* pFile = &pCreator->m_File; | 732 CFX_FileBufferArchive* pFile = &pCreator->m_File; |
| 694 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; | 733 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; |
| 695 if (bIncremental) { | 734 if (bIncremental) { |
| 696 AddObjectNumberToIndexArray(objnum); | 735 AddObjectNumberToIndexArray(objnum); |
| 697 } else { | 736 } else { |
| 698 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { | 737 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { |
| 699 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 738 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 700 if (offset) { | 739 if (offset) { |
| 701 _AppendIndex1(m_Buffer, *offset); | 740 AppendIndex1(m_Buffer, *offset); |
| 702 } else { | 741 } else { |
| 703 _AppendIndex0(m_Buffer, FALSE); | 742 AppendIndex0(m_Buffer, false); |
| 704 } | 743 } |
| 705 } | 744 } |
| 706 } | 745 } |
| 707 _AppendIndex1(m_Buffer, offset_tmp); | 746 AppendIndex1(m_Buffer, offset_tmp); |
| 708 FX_FILESIZE& offset = pCreator->m_Offset; | 747 FX_FILESIZE& offset = pCreator->m_Offset; |
| 709 int32_t len = pFile->AppendDWord(objnum); | 748 int32_t len = pFile->AppendDWord(objnum); |
| 710 if (len < 0) { | 749 if (len < 0) { |
| 711 return FALSE; | 750 return FALSE; |
| 712 } | 751 } |
| 713 offset += len; | 752 offset += len; |
| 714 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) < | 753 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) < |
| 715 0) { | 754 0) { |
| 716 return FALSE; | 755 return FALSE; |
| 717 } | 756 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 return TRUE; | 864 return TRUE; |
| 826 } | 865 } |
| 827 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { | 866 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 828 if (EndObjectStream(pCreator, bEOF) < 0) { | 867 if (EndObjectStream(pCreator, bEOF) < 0) { |
| 829 return FALSE; | 868 return FALSE; |
| 830 } | 869 } |
| 831 return GenerateXRefStream(pCreator, bEOF); | 870 return GenerateXRefStream(pCreator, bEOF); |
| 832 } | 871 } |
| 833 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { | 872 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { |
| 834 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 873 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 835 _AppendIndex0(m_Buffer); | 874 AppendIndex0(m_Buffer, true); |
| 836 for (FX_DWORD i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { | 875 for (FX_DWORD i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { |
| 837 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); | 876 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); |
| 838 if (offset) { | 877 if (offset) { |
| 839 _AppendIndex1(m_Buffer, *offset); | 878 AppendIndex1(m_Buffer, *offset); |
| 840 } else { | 879 } else { |
| 841 _AppendIndex0(m_Buffer, FALSE); | 880 AppendIndex0(m_Buffer, false); |
| 842 } | 881 } |
| 843 } | 882 } |
| 844 } else { | 883 } else { |
| 845 int32_t iSeg = m_IndexArray.GetSize() / 2; | 884 int32_t iSeg = m_IndexArray.GetSize() / 2; |
| 846 for (int i = 0; i < iSeg; i++) { | 885 for (int i = 0; i < iSeg; i++) { |
| 847 FX_DWORD start = m_IndexArray.ElementAt(i * 2); | 886 FX_DWORD start = m_IndexArray.ElementAt(i * 2); |
| 848 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; | 887 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; |
| 849 for (FX_DWORD j = start; j < end; j++) { | 888 for (FX_DWORD j = start; j < end; j++) { |
| 850 _AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); | 889 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); |
| 851 } | 890 } |
| 852 } | 891 } |
| 853 } | 892 } |
| 854 return GenerateXRefStream(pCreator, FALSE); | 893 return GenerateXRefStream(pCreator, FALSE); |
| 855 } | 894 } |
| 856 FX_BOOL CPDF_XRefStream::AddObjectNumberToIndexArray(FX_DWORD objnum) { | 895 FX_BOOL CPDF_XRefStream::AddObjectNumberToIndexArray(FX_DWORD objnum) { |
| 857 int32_t iSize = m_IndexArray.GetSize(); | 896 int32_t iSize = m_IndexArray.GetSize(); |
| 858 if (iSize == 0) { | 897 if (iSize == 0) { |
| 859 m_IndexArray.Add(objnum); | 898 m_IndexArray.Add(objnum); |
| 860 m_IndexArray.Add(1); | 899 m_IndexArray.Add(1); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 m_bNewCrypto = FALSE; | 940 m_bNewCrypto = FALSE; |
| 902 } | 941 } |
| 903 CPDF_Creator::~CPDF_Creator() { | 942 CPDF_Creator::~CPDF_Creator() { |
| 904 ResetStandardSecurity(); | 943 ResetStandardSecurity(); |
| 905 if (m_bEncryptCloned && m_pEncryptDict) { | 944 if (m_bEncryptCloned && m_pEncryptDict) { |
| 906 m_pEncryptDict->Release(); | 945 m_pEncryptDict->Release(); |
| 907 m_pEncryptDict = NULL; | 946 m_pEncryptDict = NULL; |
| 908 } | 947 } |
| 909 Clear(); | 948 Clear(); |
| 910 } | 949 } |
| 911 static FX_BOOL _IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) { | 950 |
| 912 if (!(flag & FPDFCREATE_INCREMENTAL)) { | |
| 913 return FALSE; | |
| 914 } | |
| 915 int32_t iSize = pXRef->m_IndexArray.GetSize() / 2; | |
| 916 int32_t iCount = 0; | |
| 917 for (int32_t i = 0; i < iSize; i++) { | |
| 918 iCount += pXRef->m_IndexArray.ElementAt(i * 2 + 1); | |
| 919 } | |
| 920 return (iCount >= PDF_XREFSTREAM_MAXSIZE); | |
| 921 } | |
| 922 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { | 951 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
| 923 if (!m_pXRefStream) | 952 if (!m_pXRefStream) |
| 924 return 1; | 953 return 1; |
| 925 | 954 |
| 926 FX_DWORD objnum = pObj->GetObjNum(); | 955 FX_DWORD objnum = pObj->GetObjNum(); |
| 927 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && | 956 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && |
| 928 m_pParser->m_ObjVersion[objnum] > 0) { | 957 m_pParser->m_ObjVersion[objnum] > 0) { |
| 929 return 1; | 958 return 1; |
| 930 } | 959 } |
| 931 | 960 |
| 932 if (pObj->IsNumber()) | 961 if (pObj->IsNumber()) |
| 933 return 1; | 962 return 1; |
| 934 | 963 |
| 935 CPDF_Dictionary* pDict = pObj->GetDict(); | 964 CPDF_Dictionary* pDict = pObj->GetDict(); |
| 936 if (pObj->IsStream()) | 965 if (pObj->IsStream()) { |
| 937 if (pDict && pDict->GetString("Type") == "XRef") | 966 if (pDict && pDict->GetString("Type") == "XRef") |
| 938 return 0; | 967 return 0; |
| 939 return 1; | 968 return 1; |
| 969 } |
| 940 | 970 |
| 941 if (pDict) { | 971 if (pDict) { |
| 942 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) | 972 if (pDict == m_pDocument->m_pRootDict || pDict == m_pEncryptDict) |
| 943 return 1; | 973 return 1; |
| 944 if (IsSignatureDict(pDict)) | 974 if (IsSignatureDict(pDict)) |
| 945 return 1; | 975 return 1; |
| 946 if (pDict->GetString("Type") == "Page") | 976 if (pDict->GetString("Type") == "Page") |
| 947 return 1; | 977 return 1; |
| 948 } | 978 } |
| 949 | 979 |
| 950 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 980 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 951 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 981 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
| 952 return -1; | 982 return -1; |
| 953 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 983 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) |
| 954 return 0; | 984 return 0; |
| 955 if (!m_pXRefStream->End(this)) | 985 if (!m_pXRefStream->End(this)) |
| 956 return -1; | 986 return -1; |
| 957 if (!m_pXRefStream->Start()) | 987 if (!m_pXRefStream->Start()) |
| 958 return -1; | 988 return -1; |
| 959 return 0; | 989 return 0; |
| 960 } | 990 } |
| 961 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, | 991 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, |
| 962 const uint8_t* pBuffer, | 992 const uint8_t* pBuffer, |
| 963 FX_DWORD dwSize) { | 993 FX_DWORD dwSize) { |
| 964 if (!m_pXRefStream) { | 994 if (!m_pXRefStream) { |
| 965 return 1; | 995 return 1; |
| 966 } | 996 } |
| 967 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 997 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 968 int32_t iRet = | 998 int32_t iRet = |
| 969 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 999 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
| 970 if (iRet < 1) { | 1000 if (iRet < 1) { |
| 971 return iRet; | 1001 return iRet; |
| 972 } | 1002 } |
| 973 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 1003 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 974 return 0; | 1004 return 0; |
| 975 } | 1005 } |
| 976 if (!m_pXRefStream->End(this)) { | 1006 if (!m_pXRefStream->End(this)) { |
| 977 return -1; | 1007 return -1; |
| 978 } | 1008 } |
| 979 if (!m_pXRefStream->Start()) { | 1009 if (!m_pXRefStream->Start()) { |
| 980 return -1; | 1010 return -1; |
| 981 } | 1011 } |
| 982 return 0; | 1012 return 0; |
| 983 } | 1013 } |
| 984 int32_t CPDF_Creator::AppendObjectNumberToXRef(FX_DWORD objnum) { | 1014 int32_t CPDF_Creator::AppendObjectNumberToXRef(FX_DWORD objnum) { |
| 985 if (!m_pXRefStream) { | 1015 if (!m_pXRefStream) { |
| 986 return 1; | 1016 return 1; |
| 987 } | 1017 } |
| 988 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 1018 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 989 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 1019 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 990 return 0; | 1020 return 0; |
| 991 } | 1021 } |
| 992 if (!m_pXRefStream->End(this)) { | 1022 if (!m_pXRefStream->End(this)) { |
| 993 return -1; | 1023 return -1; |
| 994 } | 1024 } |
| 995 if (!m_pXRefStream->Start()) { | 1025 if (!m_pXRefStream->Start()) { |
| 996 return -1; | 1026 return -1; |
| 997 } | 1027 } |
| 998 return 0; | 1028 return 0; |
| 999 } | 1029 } |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 } | 1746 } |
| 1717 if (pPause && (i % 100) == 0 && pPause->NeedToPauseNow()) { | 1747 if (pPause && (i % 100) == 0 && pPause->NeedToPauseNow()) { |
| 1718 m_Pos = (void*)(uintptr_t)i; | 1748 m_Pos = (void*)(uintptr_t)i; |
| 1719 return 1; | 1749 return 1; |
| 1720 } | 1750 } |
| 1721 } | 1751 } |
| 1722 m_iStage = 90; | 1752 m_iStage = 90; |
| 1723 } | 1753 } |
| 1724 return m_iStage; | 1754 return m_iStage; |
| 1725 } | 1755 } |
| 1726 static int32_t _OutPutIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { | 1756 |
| 1727 FXSYS_assert(pFile); | |
| 1728 if (sizeof(offset) > 4) { | |
| 1729 if (FX_GETBYTEOFFSET32(offset)) { | |
| 1730 if (pFile->AppendByte(FX_GETBYTEOFFSET56(offset)) < 0) { | |
| 1731 return -1; | |
| 1732 } | |
| 1733 if (pFile->AppendByte(FX_GETBYTEOFFSET48(offset)) < 0) { | |
| 1734 return -1; | |
| 1735 } | |
| 1736 if (pFile->AppendByte(FX_GETBYTEOFFSET40(offset)) < 0) { | |
| 1737 return -1; | |
| 1738 } | |
| 1739 if (pFile->AppendByte(FX_GETBYTEOFFSET32(offset)) < 0) { | |
| 1740 return -1; | |
| 1741 } | |
| 1742 } | |
| 1743 } | |
| 1744 if (pFile->AppendByte(FX_GETBYTEOFFSET24(offset)) < 0) { | |
| 1745 return -1; | |
| 1746 } | |
| 1747 if (pFile->AppendByte(FX_GETBYTEOFFSET16(offset)) < 0) { | |
| 1748 return -1; | |
| 1749 } | |
| 1750 if (pFile->AppendByte(FX_GETBYTEOFFSET8(offset)) < 0) { | |
| 1751 return -1; | |
| 1752 } | |
| 1753 if (pFile->AppendByte(FX_GETBYTEOFFSET0(offset)) < 0) { | |
| 1754 return -1; | |
| 1755 } | |
| 1756 if (pFile->AppendByte(0) < 0) { | |
| 1757 return -1; | |
| 1758 } | |
| 1759 return 0; | |
| 1760 } | |
| 1761 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { | 1757 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { |
| 1762 FXSYS_assert(m_iStage >= 90); | 1758 FXSYS_assert(m_iStage >= 90); |
| 1763 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { | 1759 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { |
| 1764 FX_BOOL bXRefStream = | 1760 FX_BOOL bXRefStream = |
| 1765 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); | 1761 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); |
| 1766 if (!bXRefStream) { | 1762 if (!bXRefStream) { |
| 1767 if (m_File.AppendString("trailer\r\n<<") < 0) { | 1763 if (m_File.AppendString("trailer\r\n<<") < 0) { |
| 1768 return -1; | 1764 return -1; |
| 1769 } | 1765 } |
| 1770 } else { | 1766 } else { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1907 return -1; | 1903 return -1; |
| 1908 } | 1904 } |
| 1909 if (m_File.AppendString(">>stream\r\n") < 0) { | 1905 if (m_File.AppendString(">>stream\r\n") < 0) { |
| 1910 return -1; | 1906 return -1; |
| 1911 } | 1907 } |
| 1912 for (i = 0; i < m_dwLastObjNum; i++) { | 1908 for (i = 0; i < m_dwLastObjNum; i++) { |
| 1913 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); | 1909 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); |
| 1914 if (!offset) { | 1910 if (!offset) { |
| 1915 continue; | 1911 continue; |
| 1916 } | 1912 } |
| 1917 _OutPutIndex(&m_File, *offset); | 1913 OutputIndex(&m_File, *offset); |
| 1918 } | 1914 } |
| 1919 } else { | 1915 } else { |
| 1920 int count = m_NewObjNumArray.GetSize(); | 1916 int count = m_NewObjNumArray.GetSize(); |
| 1921 int32_t i = 0; | 1917 int32_t i = 0; |
| 1922 for (i = 0; i < count; i++) { | 1918 for (i = 0; i < count; i++) { |
| 1923 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1919 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); |
| 1924 if (m_File.AppendDWord(objnum) < 0) { | 1920 if (m_File.AppendDWord(objnum) < 0) { |
| 1925 return -1; | 1921 return -1; |
| 1926 } | 1922 } |
| 1927 if (m_File.AppendString(" 1 ") < 0) { | 1923 if (m_File.AppendString(" 1 ") < 0) { |
| 1928 return -1; | 1924 return -1; |
| 1929 } | 1925 } |
| 1930 } | 1926 } |
| 1931 if (m_File.AppendString("]/Length ") < 0) { | 1927 if (m_File.AppendString("]/Length ") < 0) { |
| 1932 return -1; | 1928 return -1; |
| 1933 } | 1929 } |
| 1934 if (m_File.AppendDWord(count * 5) < 0) { | 1930 if (m_File.AppendDWord(count * 5) < 0) { |
| 1935 return -1; | 1931 return -1; |
| 1936 } | 1932 } |
| 1937 if (m_File.AppendString(">>stream\r\n") < 0) { | 1933 if (m_File.AppendString(">>stream\r\n") < 0) { |
| 1938 return -1; | 1934 return -1; |
| 1939 } | 1935 } |
| 1940 for (i = 0; i < count; i++) { | 1936 for (i = 0; i < count; i++) { |
| 1941 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1937 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); |
| 1942 FX_FILESIZE offset = m_ObjectOffset[objnum]; | 1938 FX_FILESIZE offset = m_ObjectOffset[objnum]; |
| 1943 _OutPutIndex(&m_File, offset); | 1939 OutputIndex(&m_File, offset); |
| 1944 } | 1940 } |
| 1945 } | 1941 } |
| 1946 if (m_File.AppendString("\r\nendstream") < 0) { | 1942 if (m_File.AppendString("\r\nendstream") < 0) { |
| 1947 return -1; | 1943 return -1; |
| 1948 } | 1944 } |
| 1949 } | 1945 } |
| 1950 } | 1946 } |
| 1951 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { | 1947 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { |
| 1952 return -1; | 1948 return -1; |
| 1953 } | 1949 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1992 InitID(); | 1988 InitID(); |
| 1993 if (flags & FPDFCREATE_PROGRESSIVE) { | 1989 if (flags & FPDFCREATE_PROGRESSIVE) { |
| 1994 return TRUE; | 1990 return TRUE; |
| 1995 } | 1991 } |
| 1996 return Continue(NULL) > -1; | 1992 return Continue(NULL) > -1; |
| 1997 } | 1993 } |
| 1998 void CPDF_Creator::InitID(FX_BOOL bDefault) { | 1994 void CPDF_Creator::InitID(FX_BOOL bDefault) { |
| 1999 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; | 1995 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; |
| 2000 FX_BOOL bNewId = !m_pIDArray; | 1996 FX_BOOL bNewId = !m_pIDArray; |
| 2001 if (!m_pIDArray) { | 1997 if (!m_pIDArray) { |
| 2002 FX_DWORD* pBuffer = NULL; | |
| 2003 m_pIDArray = new CPDF_Array; | 1998 m_pIDArray = new CPDF_Array; |
| 2004 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; | 1999 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; |
| 2005 if (pID1) { | 2000 if (pID1) { |
| 2006 m_pIDArray->Add(pID1->Clone()); | 2001 m_pIDArray->Add(pID1->Clone()); |
| 2007 } else { | 2002 } else { |
| 2008 pBuffer = FX_Alloc(FX_DWORD, 4); | 2003 std::vector<uint8_t> buffer = |
| 2009 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); | 2004 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); |
| 2010 CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); | 2005 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 2011 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2006 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 2012 } | 2007 } |
| 2013 FX_Free(pBuffer); | |
| 2014 } | 2008 } |
| 2015 if (!bDefault) { | 2009 if (!bDefault) { |
| 2016 return; | 2010 return; |
| 2017 } | 2011 } |
| 2018 if (pOldIDArray) { | 2012 if (pOldIDArray) { |
| 2019 CPDF_Object* pID2 = pOldIDArray->GetElement(1); | 2013 CPDF_Object* pID2 = pOldIDArray->GetElement(1); |
| 2020 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { | 2014 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { |
| 2021 m_pIDArray->Add(pID2->Clone()); | 2015 m_pIDArray->Add(pID2->Clone()); |
| 2022 return; | 2016 return; |
| 2023 } | 2017 } |
| 2024 FX_DWORD* pBuffer = FX_Alloc(FX_DWORD, 4); | 2018 std::vector<uint8_t> buffer = |
| 2025 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); | 2019 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum); |
| 2026 CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); | 2020 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 2027 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2021 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 2028 FX_Free(pBuffer); | |
| 2029 return; | 2022 return; |
| 2030 } | 2023 } |
| 2031 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); | 2024 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); |
| 2032 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 2025 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
| 2033 if (m_pEncryptDict->GetString("Filter") == "Standard") { | 2026 if (m_pEncryptDict->GetString("Filter") == "Standard") { |
| 2034 CPDF_StandardSecurityHandler handler; | 2027 CPDF_StandardSecurityHandler handler; |
| 2035 CFX_ByteString user_pass = m_pParser->GetPassword(); | 2028 CFX_ByteString user_pass = m_pParser->GetPassword(); |
| 2036 FX_DWORD flag = PDF_ENCRYPT_CONTENT; | 2029 FX_DWORD flag = PDF_ENCRYPT_CONTENT; |
| 2037 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, | 2030 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, |
| 2038 user_pass.GetLength(), flag); | 2031 user_pass.GetLength(), flag); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 m_bNewCrypto = FALSE; | 2086 m_bNewCrypto = FALSE; |
| 2094 if (!m_bStandardSecurity) { | 2087 if (!m_bStandardSecurity) { |
| 2095 return; | 2088 return; |
| 2096 } | 2089 } |
| 2097 if (m_pEncryptDict) { | 2090 if (m_pEncryptDict) { |
| 2098 m_pEncryptDict->Release(); | 2091 m_pEncryptDict->Release(); |
| 2099 m_pEncryptDict = NULL; | 2092 m_pEncryptDict = NULL; |
| 2100 } | 2093 } |
| 2101 m_bStandardSecurity = FALSE; | 2094 m_bStandardSecurity = FALSE; |
| 2102 } | 2095 } |
| OLD | NEW |