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

Side by Side Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 504673002: Add GetValidBpc() check in CPDF_DIBSource::CreateDecoder() (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 #include "../../../include/fxcodec/fx_codec.h" 8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "../../../include/fpdfapi/fpdf_module.h" 9 #include "../../../include/fpdfapi/fpdf_module.h"
10 #include "../../../include/fpdfapi/fpdf_render.h" 10 #include "../../../include/fpdfapi/fpdf_render.h"
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 } 551 }
552 m_bColorKey = TRUE; 552 m_bColorKey = TRUE;
553 } 553 }
554 } 554 }
555 return TRUE; 555 return TRUE;
556 } 556 }
557 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height, 557 ICodec_ScanlineDecoder* FPDFAPI_CreateFaxDecoder(FX_LPCBYTE src_buf, FX_DWORD sr c_size, int width, int height,
558 const CPDF_Dictionary* pParams); 558 const CPDF_Dictionary* pParams);
559 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, 559 ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height,
560 int nComps, int bpc, const CPDF_Dictionary* pParams); 560 int nComps, int bpc, const CPDF_Dictionary* pParams);
561 int CPDF_DIBSource::CreateDecoder() 561 int CPDF_DIBSource::CreateDecoder()
Tom Sepez 2014/08/25 17:20:11 Just curious, what does the return value from this
Bo Xu 2014/08/25 18:16:43 I am not entirely sure for now. This function can
562 { 562 {
563 FX_DWORD bpc = GetValidBpc();
Tom Sepez 2014/08/25 17:20:11 Do we need to check for the bpc == 0 case and retu
Bo Xu 2014/08/25 18:16:43 Done.
563 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 564 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
564 if (decoder.IsEmpty()) { 565 if (decoder.IsEmpty()) {
565 return 1; 566 return 1;
566 } 567 }
567 FX_LPCBYTE src_data = m_pStreamAcc->GetData(); 568 FX_LPCBYTE src_data = m_pStreamAcc->GetData();
568 FX_DWORD src_size = m_pStreamAcc->GetSize(); 569 FX_DWORD src_size = m_pStreamAcc->GetSize();
569 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 570 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
570 if (decoder == FX_BSTRC("CCITTFaxDecode")) { 571 if (decoder == FX_BSTRC("CCITTFaxDecode")) {
571 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams); 572 m_pDecoder = FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, m_Hei ght, pParams);
572 } else if (decoder == FX_BSTRC("DCTDecode")) { 573 } else if (decoder == FX_BSTRC("DCTDecode")) {
573 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height, 574 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_d ata, src_size, m_Width, m_Height,
574 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1); 575 m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("Color Transform"), 1) : 1);
575 if (NULL == m_pDecoder) { 576 if (NULL == m_pDecoder) {
576 FX_BOOL bTransform = FALSE; 577 FX_BOOL bTransform = FALSE;
577 int comps, bpc; 578 int comps;
578 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e(); 579 ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModul e();
579 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, bpc, bTransform)) { 580 if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, com ps, (FX_INT32&)bpc, bTransform)) {
Tom Sepez 2014/08/25 17:20:11 This cast looks suspicious. Maybe bpc should be an
Bo Xu 2014/08/25 18:16:43 Now I use the temporal bpc to get around this.
580 m_nComponents = comps; 581 m_nComponents = comps;
581 m_bpc = bpc; 582 m_bpc = bpc;
582 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height, 583 m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecod er(src_data, src_size, m_Width, m_Height,
583 m_nComponents, bTransform); 584 m_nComponents, bTransform);
584 } 585 }
585 } 586 }
586 } else if (decoder == FX_BSTRC("FlateDecode")) { 587 } else if (decoder == FX_BSTRC("FlateDecode")) {
587 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, m_bpc, pParams); 588 m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_H eight, m_nComponents, bpc, pParams);
588 } else if (decoder == FX_BSTRC("JPXDecode")) { 589 } else if (decoder == FX_BSTRC("JPXDecode")) {
589 LoadJpxBitmap(); 590 LoadJpxBitmap();
590 return m_pCachedBitmap != NULL ? 1 : 0; 591 return m_pCachedBitmap != NULL ? 1 : 0;
591 } else if (decoder == FX_BSTRC("JBIG2Decode")) { 592 } else if (decoder == FX_BSTRC("JBIG2Decode")) {
592 m_pCachedBitmap = FX_NEW CFX_DIBitmap; 593 m_pCachedBitmap = FX_NEW CFX_DIBitmap;
593 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) { 594 if (!m_pCachedBitmap->Create(m_Width, m_Height, m_bImageMask ? FXDIB_1bp pMask : FXDIB_1bppRgb)) {
594 delete m_pCachedBitmap; 595 delete m_pCachedBitmap;
595 m_pCachedBitmap = NULL; 596 m_pCachedBitmap = NULL;
596 return 0; 597 return 0;
597 } 598 }
598 m_Status = 1; 599 m_Status = 1;
599 return 2; 600 return 2;
600 } else if (decoder == FX_BSTRC("RunLengthDecode")) { 601 } else if (decoder == FX_BSTRC("RunLengthDecode")) {
601 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc); 602 m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()-> CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_b pc);
602 } 603 }
603 if (m_pDecoder) { 604 if (m_pDecoder) {
604 int requested_pitch = (m_Width * m_nComponents * m_bpc + 7) / 8; 605 FX_SAFE_DWORD requested_pitch = bpc;
605 int provided_pitch = (m_pDecoder->GetWidth() * m_pDecoder->CountComps() * m_pDecoder->GetBPC() + 7) / 8; 606 requested_pitch *= m_nComponents;
606 if (provided_pitch < requested_pitch) { 607 requested_pitch *= m_Width;
608 requested_pitch += 7;
609 requested_pitch /= 8;
610 if (!requested_pitch.IsValid()) {
611 return 1;
612 }
613 FX_SAFE_DWORD provided_pitch = m_pDecoder->GetBPC();
614 provided_pitch *= m_pDecoder->CountComps();
615 provided_pitch *= m_pDecoder->GetWidth();
616 provided_pitch += 7;
617 provided_pitch /= 8;
618 if (!provided_pitch.IsValid()) {
619 return 1;
620 }
621 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
607 return 0; 622 return 0;
608 } 623 }
609 return 1; 624 return 1;
610 } 625 }
611 return 0; 626 return 0;
612 } 627 }
613 void CPDF_DIBSource::LoadJpxBitmap() 628 void CPDF_DIBSource::LoadJpxBitmap()
614 { 629 {
615 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 630 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
616 if (pJpxModule == NULL) { 631 if (pJpxModule == NULL) {
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 if (!m_bCached) { 1541 if (!m_bCached) {
1527 if (m_pBitmap) { 1542 if (m_pBitmap) {
1528 delete m_pBitmap; 1543 delete m_pBitmap;
1529 m_pBitmap = NULL; 1544 m_pBitmap = NULL;
1530 } 1545 }
1531 if (m_pMask) { 1546 if (m_pMask) {
1532 delete m_pMask; 1547 delete m_pMask;
1533 } 1548 }
1534 } 1549 }
1535 } 1550 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698