Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "editint.h" | 7 #include "core/src/fpdfapi/fpdf_edit/editint.h" |
| 8 | 8 |
| 9 #include "core/include/fxcrt/fx_ext.h" | 9 #include "core/include/fxcrt/fx_ext.h" |
| 10 #include "core/include/fpdfapi/fpdf_serial.h" | 10 #include "core/include/fpdfapi/fpdf_serial.h" |
| 11 #include "core/include/fpdfapi/fpdf_parser.h" | 11 #include "core/include/fpdfapi/fpdf_parser.h" |
| 12 | 12 |
| 13 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) | 13 #define PDF_OBJECTSTREAM_MAXLENGTH (256 * 1024) |
| 14 #define PDF_XREFSTREAM_MAXSIZE 10000 | 14 #define PDF_XREFSTREAM_MAXSIZE 10000 |
| 15 | 15 |
| 16 namespace { | |
| 17 | |
| 16 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, | 18 int32_t PDF_CreatorAppendObject(const CPDF_Object* pObj, |
| 17 CFX_FileBufferArchive* pFile, | 19 CFX_FileBufferArchive* pFile, |
| 18 FX_FILESIZE& offset) { | 20 FX_FILESIZE& offset) { |
| 19 int32_t len = 0; | 21 int32_t len = 0; |
| 20 if (!pObj) { | 22 if (!pObj) { |
| 21 if (pFile->AppendString(" null") < 0) { | 23 if (pFile->AppendString(" null") < 0) { |
| 22 return -1; | 24 return -1; |
| 23 } | 25 } |
| 24 offset += 5; | 26 offset += 5; |
| 25 return 1; | 27 return 1; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 164 } |
| 163 offset += len; | 165 offset += len; |
| 164 break; | 166 break; |
| 165 } | 167 } |
| 166 default: | 168 default: |
| 167 ASSERT(FALSE); | 169 ASSERT(FALSE); |
| 168 break; | 170 break; |
| 169 } | 171 } |
| 170 return 1; | 172 return 1; |
| 171 } | 173 } |
| 174 | |
| 172 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, | 175 int32_t PDF_CreatorWriteTrailer(CPDF_Document* pDocument, |
| 173 CFX_FileBufferArchive* pFile, | 176 CFX_FileBufferArchive* pFile, |
| 174 CPDF_Array* pIDArray, | 177 CPDF_Array* pIDArray, |
| 175 FX_BOOL bCompress) { | 178 FX_BOOL bCompress) { |
| 176 FX_FILESIZE offset = 0; | 179 FX_FILESIZE offset = 0; |
| 177 int32_t len = 0; | 180 int32_t len = 0; |
| 178 FXSYS_assert(pDocument && pFile); | 181 FXSYS_assert(pDocument && pFile); |
| 179 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); | 182 CPDF_Parser* pParser = (CPDF_Parser*)pDocument->GetParser(); |
| 180 if (pParser) { | 183 if (pParser) { |
| 181 CPDF_Dictionary* p = pParser->GetTrailer(); | 184 CPDF_Dictionary* p = pParser->GetTrailer(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 if (pFile->AppendString(("/ID")) < 0) { | 255 if (pFile->AppendString(("/ID")) < 0) { |
| 253 return -1; | 256 return -1; |
| 254 } | 257 } |
| 255 offset += 3; | 258 offset += 3; |
| 256 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { | 259 if (PDF_CreatorAppendObject(pIDArray, pFile, offset) < 0) { |
| 257 return -1; | 260 return -1; |
| 258 } | 261 } |
| 259 } | 262 } |
| 260 return offset; | 263 return offset; |
| 261 } | 264 } |
| 265 | |
| 262 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, | 266 int32_t PDF_CreatorWriteEncrypt(const CPDF_Dictionary* pEncryptDict, |
| 263 FX_DWORD dwObjNum, | 267 FX_DWORD dwObjNum, |
| 264 CFX_FileBufferArchive* pFile) { | 268 CFX_FileBufferArchive* pFile) { |
| 265 if (!pEncryptDict) { | 269 if (!pEncryptDict) { |
| 266 return 0; | 270 return 0; |
| 267 } | 271 } |
| 268 FXSYS_assert(pFile); | 272 FXSYS_assert(pFile); |
| 269 FX_FILESIZE offset = 0; | 273 FX_FILESIZE offset = 0; |
| 270 int32_t len = 0; | 274 int32_t len = 0; |
| 271 if (pFile->AppendString("/Encrypt") < 0) { | 275 if (pFile->AppendString("/Encrypt") < 0) { |
| 272 return -1; | 276 return -1; |
| 273 } | 277 } |
| 274 offset += 8; | 278 offset += 8; |
| 275 if (pFile->AppendString(" ") < 0) { | 279 if (pFile->AppendString(" ") < 0) { |
| 276 return -1; | 280 return -1; |
| 277 } | 281 } |
| 278 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { | 282 if ((len = pFile->AppendDWord(dwObjNum)) < 0) { |
| 279 return -1; | 283 return -1; |
| 280 } | 284 } |
| 281 if (pFile->AppendString(" 0 R ") < 0) { | 285 if (pFile->AppendString(" 0 R ") < 0) { |
| 282 return -1; | 286 return -1; |
| 283 } | 287 } |
| 284 offset += len + 6; | 288 offset += len + 6; |
| 285 return offset; | 289 return offset; |
| 286 } | 290 } |
| 287 FX_BOOL PDF_GenerateFileID(FX_DWORD dwSeed1, | 291 |
| 288 FX_DWORD dwSeed2, | 292 void PDF_GenerateFileID(FX_DWORD dwSeed1, |
| 289 FX_DWORD* pBuffer) { | 293 FX_DWORD dwSeed2, |
| 290 if (!pBuffer) { | 294 std::vector<uint8_t>* buffer) { |
|
Tom Sepez
2016/01/07 17:27:02
nit: does RVO allow us to return this as a result
Lei Zhang
2016/01/08 02:54:30
Done.
| |
| 291 return FALSE; | 295 buffer->resize(sizeof(FX_DWORD) * 4); |
| 292 } | 296 FX_DWORD* pBuffer = reinterpret_cast<FX_DWORD*>(buffer->data()); |
| 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) |
|
Tom Sepez
2016/01/07 17:27:02
nit: worth unrolling this loop into two calls?
Lei Zhang
2016/01/08 02:54:30
Let the compiler figure it out?
Tom Sepez
2016/01/08 17:01:45
Nah, nothing to do with efficiency, I thought it r
| |
| 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 } | |
| 306 | |
| 307 void AppendIndex0(CFX_ByteTextBuf& buffer, bool bFirstObject) { | |
| 308 buffer.AppendByte(0); | |
| 309 buffer.AppendByte(0); | |
| 310 buffer.AppendByte(0); | |
| 311 buffer.AppendByte(0); | |
| 312 buffer.AppendByte(0); | |
| 313 if (bFirstObject) { | |
|
Tom Sepez
2016/01/07 17:27:02
nit: maybe
uint8_t byte = bFirstObject ? 0xFF :
Lei Zhang
2016/01/08 02:54:30
Done.
| |
| 314 buffer.AppendByte(0xFF); | |
| 315 buffer.AppendByte(0xFF); | |
| 316 } else { | |
| 317 buffer.AppendByte(0); | |
| 318 buffer.AppendByte(0); | |
| 302 } | 319 } |
| 303 FX_Random_MT_Close(pContext); | |
| 304 return TRUE; | |
| 305 } | 320 } |
| 321 | |
| 322 void AppendIndex1(CFX_ByteTextBuf& buffer, FX_FILESIZE offset) { | |
| 323 buffer.AppendByte(1); | |
| 324 buffer.AppendByte(FX_GETBYTEOFFSET24(offset)); | |
| 325 buffer.AppendByte(FX_GETBYTEOFFSET16(offset)); | |
| 326 buffer.AppendByte(FX_GETBYTEOFFSET8(offset)); | |
| 327 buffer.AppendByte(FX_GETBYTEOFFSET0(offset)); | |
| 328 buffer.AppendByte(0); | |
| 329 buffer.AppendByte(0); | |
| 330 } | |
| 331 | |
| 332 void AppendIndex2(CFX_ByteTextBuf& buffer, FX_DWORD objnum, int32_t index) { | |
| 333 buffer.AppendByte(2); | |
| 334 buffer.AppendByte(FX_GETBYTEOFFSET24(objnum)); | |
| 335 buffer.AppendByte(FX_GETBYTEOFFSET16(objnum)); | |
| 336 buffer.AppendByte(FX_GETBYTEOFFSET8(objnum)); | |
| 337 buffer.AppendByte(FX_GETBYTEOFFSET0(objnum)); | |
| 338 buffer.AppendByte(FX_GETBYTEOFFSET8(index)); | |
| 339 buffer.AppendByte(FX_GETBYTEOFFSET0(index)); | |
| 340 } | |
| 341 | |
| 342 bool IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) { | |
| 343 if (!(flag & FPDFCREATE_INCREMENTAL)) | |
| 344 return false; | |
| 345 | |
| 346 int32_t iSize = pXRef->m_IndexArray.GetSize() / 2; | |
| 347 int32_t iCount = 0; | |
| 348 for (int32_t i = 0; i < iSize; ++i) | |
| 349 iCount += pXRef->m_IndexArray.ElementAt(i * 2 + 1); | |
| 350 return iCount >= PDF_XREFSTREAM_MAXSIZE; | |
| 351 } | |
| 352 | |
| 353 int32_t OutPutIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { | |
|
Tom Sepez
2016/01/07 17:27:02
nit: OutputIndex
Lei Zhang
2016/01/08 02:54:30
Done.
| |
| 354 FXSYS_assert(pFile); | |
|
Tom Sepez
2016/01/07 17:27:02
nit: not needed.
Lei Zhang
2016/01/08 02:54:30
Done.
| |
| 355 if (sizeof(offset) > 4) { | |
| 356 if (FX_GETBYTEOFFSET32(offset)) { | |
| 357 if (pFile->AppendByte(FX_GETBYTEOFFSET56(offset)) < 0) { | |
|
Tom Sepez
2016/01/07 17:27:02
nit: {} not required.
Lei Zhang
2016/01/08 02:54:30
Done.
| |
| 358 return -1; | |
| 359 } | |
| 360 if (pFile->AppendByte(FX_GETBYTEOFFSET48(offset)) < 0) { | |
| 361 return -1; | |
| 362 } | |
| 363 if (pFile->AppendByte(FX_GETBYTEOFFSET40(offset)) < 0) { | |
| 364 return -1; | |
| 365 } | |
| 366 if (pFile->AppendByte(FX_GETBYTEOFFSET32(offset)) < 0) { | |
| 367 return -1; | |
| 368 } | |
| 369 } | |
| 370 } | |
| 371 if (pFile->AppendByte(FX_GETBYTEOFFSET24(offset)) < 0) { | |
| 372 return -1; | |
| 373 } | |
| 374 if (pFile->AppendByte(FX_GETBYTEOFFSET16(offset)) < 0) { | |
| 375 return -1; | |
| 376 } | |
| 377 if (pFile->AppendByte(FX_GETBYTEOFFSET8(offset)) < 0) { | |
| 378 return -1; | |
| 379 } | |
| 380 if (pFile->AppendByte(FX_GETBYTEOFFSET0(offset)) < 0) { | |
| 381 return -1; | |
| 382 } | |
| 383 if (pFile->AppendByte(0) < 0) { | |
| 384 return -1; | |
| 385 } | |
| 386 return 0; | |
| 387 } | |
| 388 | |
| 306 class CPDF_FlateEncoder { | 389 class CPDF_FlateEncoder { |
| 307 public: | 390 public: |
| 308 CPDF_FlateEncoder(); | 391 CPDF_FlateEncoder(); |
| 309 ~CPDF_FlateEncoder(); | 392 ~CPDF_FlateEncoder(); |
| 310 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); | 393 FX_BOOL Initialize(CPDF_Stream* pStream, FX_BOOL bFlateEncode); |
| 311 FX_BOOL Initialize(const uint8_t* pBuffer, | 394 FX_BOOL Initialize(const uint8_t* pBuffer, |
| 312 FX_DWORD size, | 395 FX_DWORD size, |
| 313 FX_BOOL bFlateEncode, | 396 FX_BOOL bFlateEncode, |
| 314 FX_BOOL bXRefStream = FALSE); | 397 FX_BOOL bXRefStream = FALSE); |
| 315 void CloneDict(); | 398 void CloneDict(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 m_pData = FX_Alloc(uint8_t, m_dwSize); | 509 m_pData = FX_Alloc(uint8_t, m_dwSize); |
| 427 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); | 510 pHandler->EncryptContent(objnum, 0, src_data, src_size, m_pData, m_dwSize); |
| 428 m_bNewBuf = TRUE; | 511 m_bNewBuf = TRUE; |
| 429 return TRUE; | 512 return TRUE; |
| 430 } | 513 } |
| 431 CPDF_Encryptor::~CPDF_Encryptor() { | 514 CPDF_Encryptor::~CPDF_Encryptor() { |
| 432 if (m_bNewBuf) { | 515 if (m_bNewBuf) { |
| 433 FX_Free(m_pData); | 516 FX_Free(m_pData); |
| 434 } | 517 } |
| 435 } | 518 } |
| 519 | |
| 520 } // namespace | |
| 521 | |
| 436 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} | 522 CPDF_ObjectStream::CPDF_ObjectStream() : m_dwObjNum(0), m_index(0) {} |
| 437 FX_BOOL CPDF_ObjectStream::Start() { | 523 FX_BOOL CPDF_ObjectStream::Start() { |
| 438 m_ObjNumArray.RemoveAll(); | 524 m_ObjNumArray.RemoveAll(); |
| 439 m_OffsetArray.RemoveAll(); | 525 m_OffsetArray.RemoveAll(); |
| 440 m_Buffer.Clear(); | 526 m_Buffer.Clear(); |
| 441 m_dwObjNum = 0; | 527 m_dwObjNum = 0; |
| 442 m_index = 0; | 528 m_index = 0; |
| 443 return TRUE; | 529 return TRUE; |
| 444 } | 530 } |
| 445 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, | 531 int32_t CPDF_ObjectStream::CompressIndirectObject(FX_DWORD dwObjNum, |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 if (!pCreator) { | 661 if (!pCreator) { |
| 576 return 0; | 662 return 0; |
| 577 } | 663 } |
| 578 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); | 664 m_ObjStream.CompressIndirectObject(dwObjNum, pBuffer, dwSize); |
| 579 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && | 665 if (m_ObjStream.m_ObjNumArray.GetSize() < pCreator->m_ObjectStreamSize && |
| 580 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { | 666 m_ObjStream.m_Buffer.GetLength() < PDF_OBJECTSTREAM_MAXLENGTH) { |
| 581 return 1; | 667 return 1; |
| 582 } | 668 } |
| 583 return EndObjectStream(pCreator); | 669 return EndObjectStream(pCreator); |
| 584 } | 670 } |
| 585 static void _AppendIndex0(CFX_ByteTextBuf& buffer, | 671 |
| 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) { | 672 int32_t CPDF_XRefStream::EndObjectStream(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 621 FX_FILESIZE objOffset = 0; | 673 FX_FILESIZE objOffset = 0; |
| 622 if (bEOF) { | 674 if (bEOF) { |
| 623 objOffset = m_ObjStream.End(pCreator); | 675 objOffset = m_ObjStream.End(pCreator); |
| 624 if (objOffset < 0) { | 676 if (objOffset < 0) { |
| 625 return -1; | 677 return -1; |
| 626 } | 678 } |
| 627 } | 679 } |
| 628 FX_DWORD& dwObjStmNum = m_ObjStream.m_dwObjNum; | 680 FX_DWORD& dwObjStmNum = m_ObjStream.m_dwObjNum; |
| 629 if (!dwObjStmNum) { | 681 if (!dwObjStmNum) { |
| 630 dwObjStmNum = ++pCreator->m_dwLastObjNum; | 682 dwObjStmNum = ++pCreator->m_dwLastObjNum; |
| 631 } | 683 } |
| 632 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); | 684 int32_t iSize = m_ObjStream.m_ObjNumArray.GetSize(); |
| 633 int32_t iSeg = m_IndexArray.GetSize() / 2; | 685 int32_t iSeg = m_IndexArray.GetSize() / 2; |
| 634 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 686 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 635 if (m_dwTempObjNum == 0) { | 687 if (m_dwTempObjNum == 0) { |
| 636 _AppendIndex0(m_Buffer); | 688 AppendIndex0(m_Buffer, true); |
| 637 m_dwTempObjNum++; | 689 m_dwTempObjNum++; |
| 638 } | 690 } |
| 639 FX_DWORD end_num = m_IndexArray.GetAt((iSeg - 1) * 2) + | 691 FX_DWORD end_num = m_IndexArray.GetAt((iSeg - 1) * 2) + |
| 640 m_IndexArray.GetAt((iSeg - 1) * 2 + 1); | 692 m_IndexArray.GetAt((iSeg - 1) * 2 + 1); |
| 641 int index = 0; | 693 int index = 0; |
| 642 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { | 694 for (; m_dwTempObjNum < end_num; m_dwTempObjNum++) { |
| 643 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 695 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 644 if (offset) { | 696 if (offset) { |
| 645 if (index >= iSize || | 697 if (index >= iSize || |
| 646 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { | 698 m_dwTempObjNum != m_ObjStream.m_ObjNumArray[index]) { |
| 647 _AppendIndex1(m_Buffer, *offset); | 699 AppendIndex1(m_Buffer, *offset); |
| 648 } else { | 700 } else { |
| 649 _AppendIndex2(m_Buffer, dwObjStmNum, index++); | 701 AppendIndex2(m_Buffer, dwObjStmNum, index++); |
| 650 } | 702 } |
| 651 } else { | 703 } else { |
| 652 _AppendIndex0(m_Buffer, FALSE); | 704 AppendIndex0(m_Buffer, false); |
| 653 } | 705 } |
| 654 } | 706 } |
| 655 if (iSize > 0 && bEOF) { | 707 if (iSize > 0 && bEOF) { |
| 656 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); | 708 pCreator->m_ObjectOffset.Add(dwObjStmNum, 1); |
| 657 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; | 709 pCreator->m_ObjectOffset[dwObjStmNum] = objOffset; |
| 658 } | 710 } |
| 659 m_iSeg = iSeg; | 711 m_iSeg = iSeg; |
| 660 if (bEOF) { | 712 if (bEOF) { |
| 661 m_ObjStream.Start(); | 713 m_ObjStream.Start(); |
| 662 } | 714 } |
| 663 return 1; | 715 return 1; |
| 664 } | 716 } |
| 665 int32_t& j = m_ObjStream.m_index; | 717 int32_t& j = m_ObjStream.m_index; |
| 666 for (int i = m_iSeg; i < iSeg; i++) { | 718 for (int i = m_iSeg; i < iSeg; i++) { |
| 667 FX_DWORD start = m_IndexArray.ElementAt(i * 2); | 719 FX_DWORD start = m_IndexArray.ElementAt(i * 2); |
| 668 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; | 720 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; |
| 669 for (FX_DWORD m = start; m < end; m++) { | 721 for (FX_DWORD m = start; m < end; m++) { |
| 670 if (j >= iSize || m != m_ObjStream.m_ObjNumArray.ElementAt(j)) { | 722 if (j >= iSize || m != m_ObjStream.m_ObjNumArray.ElementAt(j)) { |
| 671 _AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); | 723 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[m]); |
| 672 } else { | 724 } else { |
| 673 _AppendIndex2(m_Buffer, dwObjStmNum, j++); | 725 AppendIndex2(m_Buffer, dwObjStmNum, j++); |
| 674 } | 726 } |
| 675 } | 727 } |
| 676 } | 728 } |
| 677 if (iSize > 0 && bEOF) { | 729 if (iSize > 0 && bEOF) { |
| 678 _AppendIndex1(m_Buffer, objOffset); | 730 AppendIndex1(m_Buffer, objOffset); |
| 679 m_IndexArray.Add(dwObjStmNum); | 731 m_IndexArray.Add(dwObjStmNum); |
| 680 m_IndexArray.Add(1); | 732 m_IndexArray.Add(1); |
| 681 iSeg += 1; | 733 iSeg += 1; |
| 682 } | 734 } |
| 683 m_iSeg = iSeg; | 735 m_iSeg = iSeg; |
| 684 if (bEOF) { | 736 if (bEOF) { |
| 685 m_ObjStream.Start(); | 737 m_ObjStream.Start(); |
| 686 } | 738 } |
| 687 return 1; | 739 return 1; |
| 688 } | 740 } |
| 689 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, | 741 FX_BOOL CPDF_XRefStream::GenerateXRefStream(CPDF_Creator* pCreator, |
| 690 FX_BOOL bEOF) { | 742 FX_BOOL bEOF) { |
| 691 FX_FILESIZE offset_tmp = pCreator->m_Offset; | 743 FX_FILESIZE offset_tmp = pCreator->m_Offset; |
| 692 FX_DWORD objnum = ++pCreator->m_dwLastObjNum; | 744 FX_DWORD objnum = ++pCreator->m_dwLastObjNum; |
| 693 CFX_FileBufferArchive* pFile = &pCreator->m_File; | 745 CFX_FileBufferArchive* pFile = &pCreator->m_File; |
| 694 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; | 746 FX_BOOL bIncremental = (pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL) != 0; |
| 695 if (bIncremental) { | 747 if (bIncremental) { |
| 696 AddObjectNumberToIndexArray(objnum); | 748 AddObjectNumberToIndexArray(objnum); |
| 697 } else { | 749 } else { |
| 698 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { | 750 for (; m_dwTempObjNum < pCreator->m_dwLastObjNum; m_dwTempObjNum++) { |
| 699 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); | 751 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(m_dwTempObjNum); |
| 700 if (offset) { | 752 if (offset) { |
| 701 _AppendIndex1(m_Buffer, *offset); | 753 AppendIndex1(m_Buffer, *offset); |
| 702 } else { | 754 } else { |
| 703 _AppendIndex0(m_Buffer, FALSE); | 755 AppendIndex0(m_Buffer, false); |
| 704 } | 756 } |
| 705 } | 757 } |
| 706 } | 758 } |
| 707 _AppendIndex1(m_Buffer, offset_tmp); | 759 AppendIndex1(m_Buffer, offset_tmp); |
| 708 FX_FILESIZE& offset = pCreator->m_Offset; | 760 FX_FILESIZE& offset = pCreator->m_Offset; |
| 709 int32_t len = pFile->AppendDWord(objnum); | 761 int32_t len = pFile->AppendDWord(objnum); |
| 710 if (len < 0) { | 762 if (len < 0) { |
| 711 return FALSE; | 763 return FALSE; |
| 712 } | 764 } |
| 713 offset += len; | 765 offset += len; |
| 714 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) < | 766 if ((len = pFile->AppendString(" 0 obj\r\n<</Type /XRef/W[1 4 2]/Index[")) < |
| 715 0) { | 767 0) { |
| 716 return FALSE; | 768 return FALSE; |
| 717 } | 769 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 return TRUE; | 877 return TRUE; |
| 826 } | 878 } |
| 827 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { | 879 FX_BOOL CPDF_XRefStream::End(CPDF_Creator* pCreator, FX_BOOL bEOF) { |
| 828 if (EndObjectStream(pCreator, bEOF) < 0) { | 880 if (EndObjectStream(pCreator, bEOF) < 0) { |
| 829 return FALSE; | 881 return FALSE; |
| 830 } | 882 } |
| 831 return GenerateXRefStream(pCreator, bEOF); | 883 return GenerateXRefStream(pCreator, bEOF); |
| 832 } | 884 } |
| 833 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { | 885 FX_BOOL CPDF_XRefStream::EndXRefStream(CPDF_Creator* pCreator) { |
| 834 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { | 886 if (!(pCreator->m_dwFlags & FPDFCREATE_INCREMENTAL)) { |
| 835 _AppendIndex0(m_Buffer); | 887 AppendIndex0(m_Buffer, true); |
| 836 for (FX_DWORD i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { | 888 for (FX_DWORD i = 1; i < pCreator->m_dwLastObjNum + 1; i++) { |
| 837 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); | 889 FX_FILESIZE* offset = pCreator->m_ObjectOffset.GetPtrAt(i); |
| 838 if (offset) { | 890 if (offset) { |
| 839 _AppendIndex1(m_Buffer, *offset); | 891 AppendIndex1(m_Buffer, *offset); |
| 840 } else { | 892 } else { |
| 841 _AppendIndex0(m_Buffer, FALSE); | 893 AppendIndex0(m_Buffer, false); |
| 842 } | 894 } |
| 843 } | 895 } |
| 844 } else { | 896 } else { |
| 845 int32_t iSeg = m_IndexArray.GetSize() / 2; | 897 int32_t iSeg = m_IndexArray.GetSize() / 2; |
| 846 for (int i = 0; i < iSeg; i++) { | 898 for (int i = 0; i < iSeg; i++) { |
| 847 FX_DWORD start = m_IndexArray.ElementAt(i * 2); | 899 FX_DWORD start = m_IndexArray.ElementAt(i * 2); |
| 848 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; | 900 FX_DWORD end = m_IndexArray.ElementAt(i * 2 + 1) + start; |
| 849 for (FX_DWORD j = start; j < end; j++) { | 901 for (FX_DWORD j = start; j < end; j++) { |
| 850 _AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); | 902 AppendIndex1(m_Buffer, pCreator->m_ObjectOffset[j]); |
| 851 } | 903 } |
| 852 } | 904 } |
| 853 } | 905 } |
| 854 return GenerateXRefStream(pCreator, FALSE); | 906 return GenerateXRefStream(pCreator, FALSE); |
| 855 } | 907 } |
| 856 FX_BOOL CPDF_XRefStream::AddObjectNumberToIndexArray(FX_DWORD objnum) { | 908 FX_BOOL CPDF_XRefStream::AddObjectNumberToIndexArray(FX_DWORD objnum) { |
| 857 int32_t iSize = m_IndexArray.GetSize(); | 909 int32_t iSize = m_IndexArray.GetSize(); |
| 858 if (iSize == 0) { | 910 if (iSize == 0) { |
| 859 m_IndexArray.Add(objnum); | 911 m_IndexArray.Add(objnum); |
| 860 m_IndexArray.Add(1); | 912 m_IndexArray.Add(1); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 901 m_bNewCrypto = FALSE; | 953 m_bNewCrypto = FALSE; |
| 902 } | 954 } |
| 903 CPDF_Creator::~CPDF_Creator() { | 955 CPDF_Creator::~CPDF_Creator() { |
| 904 ResetStandardSecurity(); | 956 ResetStandardSecurity(); |
| 905 if (m_bEncryptCloned && m_pEncryptDict) { | 957 if (m_bEncryptCloned && m_pEncryptDict) { |
| 906 m_pEncryptDict->Release(); | 958 m_pEncryptDict->Release(); |
| 907 m_pEncryptDict = NULL; | 959 m_pEncryptDict = NULL; |
| 908 } | 960 } |
| 909 Clear(); | 961 Clear(); |
| 910 } | 962 } |
| 911 static FX_BOOL _IsXRefNeedEnd(CPDF_XRefStream* pXRef, FX_DWORD flag) { | 963 |
| 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) { | 964 int32_t CPDF_Creator::WriteIndirectObjectToStream(const CPDF_Object* pObj) { |
| 923 if (!m_pXRefStream) | 965 if (!m_pXRefStream) |
| 924 return 1; | 966 return 1; |
| 925 | 967 |
| 926 FX_DWORD objnum = pObj->GetObjNum(); | 968 FX_DWORD objnum = pObj->GetObjNum(); |
| 927 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && | 969 if (m_pParser && m_pParser->m_ObjVersion.GetSize() > (int32_t)objnum && |
| 928 m_pParser->m_ObjVersion[objnum] > 0) { | 970 m_pParser->m_ObjVersion[objnum] > 0) { |
| 929 return 1; | 971 return 1; |
| 930 } | 972 } |
| 931 | 973 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 943 return 1; | 985 return 1; |
| 944 if (IsSignatureDict(pDict)) | 986 if (IsSignatureDict(pDict)) |
| 945 return 1; | 987 return 1; |
| 946 if (pDict->GetString("Type") == "Page") | 988 if (pDict->GetString("Type") == "Page") |
| 947 return 1; | 989 return 1; |
| 948 } | 990 } |
| 949 | 991 |
| 950 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 992 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 951 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) | 993 if (m_pXRefStream->CompressIndirectObject(objnum, pObj, this) < 0) |
| 952 return -1; | 994 return -1; |
| 953 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) | 995 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) |
| 954 return 0; | 996 return 0; |
| 955 if (!m_pXRefStream->End(this)) | 997 if (!m_pXRefStream->End(this)) |
| 956 return -1; | 998 return -1; |
| 957 if (!m_pXRefStream->Start()) | 999 if (!m_pXRefStream->Start()) |
| 958 return -1; | 1000 return -1; |
| 959 return 0; | 1001 return 0; |
| 960 } | 1002 } |
| 961 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, | 1003 int32_t CPDF_Creator::WriteIndirectObjectToStream(FX_DWORD objnum, |
| 962 const uint8_t* pBuffer, | 1004 const uint8_t* pBuffer, |
| 963 FX_DWORD dwSize) { | 1005 FX_DWORD dwSize) { |
| 964 if (!m_pXRefStream) { | 1006 if (!m_pXRefStream) { |
| 965 return 1; | 1007 return 1; |
| 966 } | 1008 } |
| 967 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 1009 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 968 int32_t iRet = | 1010 int32_t iRet = |
| 969 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); | 1011 m_pXRefStream->CompressIndirectObject(objnum, pBuffer, dwSize, this); |
| 970 if (iRet < 1) { | 1012 if (iRet < 1) { |
| 971 return iRet; | 1013 return iRet; |
| 972 } | 1014 } |
| 973 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 1015 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 974 return 0; | 1016 return 0; |
| 975 } | 1017 } |
| 976 if (!m_pXRefStream->End(this)) { | 1018 if (!m_pXRefStream->End(this)) { |
| 977 return -1; | 1019 return -1; |
| 978 } | 1020 } |
| 979 if (!m_pXRefStream->Start()) { | 1021 if (!m_pXRefStream->Start()) { |
| 980 return -1; | 1022 return -1; |
| 981 } | 1023 } |
| 982 return 0; | 1024 return 0; |
| 983 } | 1025 } |
| 984 int32_t CPDF_Creator::AppendObjectNumberToXRef(FX_DWORD objnum) { | 1026 int32_t CPDF_Creator::AppendObjectNumberToXRef(FX_DWORD objnum) { |
| 985 if (!m_pXRefStream) { | 1027 if (!m_pXRefStream) { |
| 986 return 1; | 1028 return 1; |
| 987 } | 1029 } |
| 988 m_pXRefStream->AddObjectNumberToIndexArray(objnum); | 1030 m_pXRefStream->AddObjectNumberToIndexArray(objnum); |
| 989 if (!_IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { | 1031 if (!IsXRefNeedEnd(m_pXRefStream, m_dwFlags)) { |
| 990 return 0; | 1032 return 0; |
| 991 } | 1033 } |
| 992 if (!m_pXRefStream->End(this)) { | 1034 if (!m_pXRefStream->End(this)) { |
| 993 return -1; | 1035 return -1; |
| 994 } | 1036 } |
| 995 if (!m_pXRefStream->Start()) { | 1037 if (!m_pXRefStream->Start()) { |
| 996 return -1; | 1038 return -1; |
| 997 } | 1039 } |
| 998 return 0; | 1040 return 0; |
| 999 } | 1041 } |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1716 } | 1758 } |
| 1717 if (pPause && (i % 100) == 0 && pPause->NeedToPauseNow()) { | 1759 if (pPause && (i % 100) == 0 && pPause->NeedToPauseNow()) { |
| 1718 m_Pos = (void*)(uintptr_t)i; | 1760 m_Pos = (void*)(uintptr_t)i; |
| 1719 return 1; | 1761 return 1; |
| 1720 } | 1762 } |
| 1721 } | 1763 } |
| 1722 m_iStage = 90; | 1764 m_iStage = 90; |
| 1723 } | 1765 } |
| 1724 return m_iStage; | 1766 return m_iStage; |
| 1725 } | 1767 } |
| 1726 static int32_t _OutPutIndex(CFX_FileBufferArchive* pFile, FX_FILESIZE offset) { | 1768 |
| 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) { | 1769 int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) { |
| 1762 FXSYS_assert(m_iStage >= 90); | 1770 FXSYS_assert(m_iStage >= 90); |
| 1763 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { | 1771 if ((m_dwFlags & FPDFCREATE_OBJECTSTREAM) == 0) { |
| 1764 FX_BOOL bXRefStream = | 1772 FX_BOOL bXRefStream = |
| 1765 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); | 1773 (m_dwFlags & FPDFCREATE_INCREMENTAL) != 0 && m_pParser->IsXRefStream(); |
| 1766 if (!bXRefStream) { | 1774 if (!bXRefStream) { |
| 1767 if (m_File.AppendString("trailer\r\n<<") < 0) { | 1775 if (m_File.AppendString("trailer\r\n<<") < 0) { |
| 1768 return -1; | 1776 return -1; |
| 1769 } | 1777 } |
| 1770 } else { | 1778 } else { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1907 return -1; | 1915 return -1; |
| 1908 } | 1916 } |
| 1909 if (m_File.AppendString(">>stream\r\n") < 0) { | 1917 if (m_File.AppendString(">>stream\r\n") < 0) { |
| 1910 return -1; | 1918 return -1; |
| 1911 } | 1919 } |
| 1912 for (i = 0; i < m_dwLastObjNum; i++) { | 1920 for (i = 0; i < m_dwLastObjNum; i++) { |
| 1913 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); | 1921 FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i); |
| 1914 if (!offset) { | 1922 if (!offset) { |
| 1915 continue; | 1923 continue; |
| 1916 } | 1924 } |
| 1917 _OutPutIndex(&m_File, *offset); | 1925 OutPutIndex(&m_File, *offset); |
| 1918 } | 1926 } |
| 1919 } else { | 1927 } else { |
| 1920 int count = m_NewObjNumArray.GetSize(); | 1928 int count = m_NewObjNumArray.GetSize(); |
| 1921 int32_t i = 0; | 1929 int32_t i = 0; |
| 1922 for (i = 0; i < count; i++) { | 1930 for (i = 0; i < count; i++) { |
| 1923 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1931 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); |
| 1924 if (m_File.AppendDWord(objnum) < 0) { | 1932 if (m_File.AppendDWord(objnum) < 0) { |
| 1925 return -1; | 1933 return -1; |
| 1926 } | 1934 } |
| 1927 if (m_File.AppendString(" 1 ") < 0) { | 1935 if (m_File.AppendString(" 1 ") < 0) { |
| 1928 return -1; | 1936 return -1; |
| 1929 } | 1937 } |
| 1930 } | 1938 } |
| 1931 if (m_File.AppendString("]/Length ") < 0) { | 1939 if (m_File.AppendString("]/Length ") < 0) { |
| 1932 return -1; | 1940 return -1; |
| 1933 } | 1941 } |
| 1934 if (m_File.AppendDWord(count * 5) < 0) { | 1942 if (m_File.AppendDWord(count * 5) < 0) { |
| 1935 return -1; | 1943 return -1; |
| 1936 } | 1944 } |
| 1937 if (m_File.AppendString(">>stream\r\n") < 0) { | 1945 if (m_File.AppendString(">>stream\r\n") < 0) { |
| 1938 return -1; | 1946 return -1; |
| 1939 } | 1947 } |
| 1940 for (i = 0; i < count; i++) { | 1948 for (i = 0; i < count; i++) { |
| 1941 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); | 1949 FX_DWORD objnum = m_NewObjNumArray.ElementAt(i); |
| 1942 FX_FILESIZE offset = m_ObjectOffset[objnum]; | 1950 FX_FILESIZE offset = m_ObjectOffset[objnum]; |
| 1943 _OutPutIndex(&m_File, offset); | 1951 OutPutIndex(&m_File, offset); |
| 1944 } | 1952 } |
| 1945 } | 1953 } |
| 1946 if (m_File.AppendString("\r\nendstream") < 0) { | 1954 if (m_File.AppendString("\r\nendstream") < 0) { |
| 1947 return -1; | 1955 return -1; |
| 1948 } | 1956 } |
| 1949 } | 1957 } |
| 1950 } | 1958 } |
| 1951 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { | 1959 if (m_File.AppendString("\r\nstartxref\r\n") < 0) { |
| 1952 return -1; | 1960 return -1; |
| 1953 } | 1961 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1992 InitID(); | 2000 InitID(); |
| 1993 if (flags & FPDFCREATE_PROGRESSIVE) { | 2001 if (flags & FPDFCREATE_PROGRESSIVE) { |
| 1994 return TRUE; | 2002 return TRUE; |
| 1995 } | 2003 } |
| 1996 return Continue(NULL) > -1; | 2004 return Continue(NULL) > -1; |
| 1997 } | 2005 } |
| 1998 void CPDF_Creator::InitID(FX_BOOL bDefault) { | 2006 void CPDF_Creator::InitID(FX_BOOL bDefault) { |
| 1999 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; | 2007 CPDF_Array* pOldIDArray = m_pParser ? m_pParser->GetIDArray() : NULL; |
| 2000 FX_BOOL bNewId = !m_pIDArray; | 2008 FX_BOOL bNewId = !m_pIDArray; |
| 2001 if (!m_pIDArray) { | 2009 if (!m_pIDArray) { |
| 2002 FX_DWORD* pBuffer = NULL; | |
| 2003 m_pIDArray = new CPDF_Array; | 2010 m_pIDArray = new CPDF_Array; |
| 2004 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; | 2011 CPDF_Object* pID1 = pOldIDArray ? pOldIDArray->GetElement(0) : NULL; |
| 2005 if (pID1) { | 2012 if (pID1) { |
| 2006 m_pIDArray->Add(pID1->Clone()); | 2013 m_pIDArray->Add(pID1->Clone()); |
| 2007 } else { | 2014 } else { |
| 2008 pBuffer = FX_Alloc(FX_DWORD, 4); | 2015 std::vector<uint8_t> buffer; |
| 2009 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); | 2016 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, &buffer); |
| 2010 CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); | 2017 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 2011 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2018 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 2012 } | 2019 } |
| 2013 FX_Free(pBuffer); | |
| 2014 } | 2020 } |
| 2015 if (!bDefault) { | 2021 if (!bDefault) { |
| 2016 return; | 2022 return; |
| 2017 } | 2023 } |
| 2018 if (pOldIDArray) { | 2024 if (pOldIDArray) { |
| 2019 CPDF_Object* pID2 = pOldIDArray->GetElement(1); | 2025 CPDF_Object* pID2 = pOldIDArray->GetElement(1); |
| 2020 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { | 2026 if ((m_dwFlags & FPDFCREATE_INCREMENTAL) && m_pEncryptDict && pID2) { |
| 2021 m_pIDArray->Add(pID2->Clone()); | 2027 m_pIDArray->Add(pID2->Clone()); |
| 2022 return; | 2028 return; |
| 2023 } | 2029 } |
| 2024 FX_DWORD* pBuffer = FX_Alloc(FX_DWORD, 4); | 2030 std::vector<uint8_t> buffer; |
| 2025 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, pBuffer); | 2031 PDF_GenerateFileID((FX_DWORD)(uintptr_t) this, m_dwLastObjNum, &buffer); |
| 2026 CFX_ByteStringC bsBuffer((const uint8_t*)pBuffer, 4 * sizeof(FX_DWORD)); | 2032 CFX_ByteStringC bsBuffer(buffer.data(), buffer.size()); |
| 2027 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); | 2033 m_pIDArray->Add(new CPDF_String(bsBuffer, TRUE), m_pDocument); |
| 2028 FX_Free(pBuffer); | |
| 2029 return; | 2034 return; |
| 2030 } | 2035 } |
| 2031 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); | 2036 m_pIDArray->Add(m_pIDArray->GetElement(0)->Clone()); |
| 2032 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { | 2037 if (m_pEncryptDict && !pOldIDArray && m_pParser && bNewId) { |
| 2033 if (m_pEncryptDict->GetString("Filter") == "Standard") { | 2038 if (m_pEncryptDict->GetString("Filter") == "Standard") { |
| 2034 CPDF_StandardSecurityHandler handler; | 2039 CPDF_StandardSecurityHandler handler; |
| 2035 CFX_ByteString user_pass = m_pParser->GetPassword(); | 2040 CFX_ByteString user_pass = m_pParser->GetPassword(); |
| 2036 FX_DWORD flag = PDF_ENCRYPT_CONTENT; | 2041 FX_DWORD flag = PDF_ENCRYPT_CONTENT; |
| 2037 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, | 2042 handler.OnCreate(m_pEncryptDict, m_pIDArray, (const uint8_t*)user_pass, |
| 2038 user_pass.GetLength(), flag); | 2043 user_pass.GetLength(), flag); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2093 m_bNewCrypto = FALSE; | 2098 m_bNewCrypto = FALSE; |
| 2094 if (!m_bStandardSecurity) { | 2099 if (!m_bStandardSecurity) { |
| 2095 return; | 2100 return; |
| 2096 } | 2101 } |
| 2097 if (m_pEncryptDict) { | 2102 if (m_pEncryptDict) { |
| 2098 m_pEncryptDict->Release(); | 2103 m_pEncryptDict->Release(); |
| 2099 m_pEncryptDict = NULL; | 2104 m_pEncryptDict = NULL; |
| 2100 } | 2105 } |
| 2101 m_bStandardSecurity = FALSE; | 2106 m_bStandardSecurity = FALSE; |
| 2102 } | 2107 } |
| OLD | NEW |