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

Side by Side Diff: core/fpdfapi/render/fpdf_render_loadimage.cpp

Issue 2486123002: Relax colorspace checks in CPDF_DIBSource::CreateDecoder(). (Closed)
Patch Set: address simple nits Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/page/fpdf_page_colors.cpp ('k') | core/fxcodec/fx_codec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/render/render_int.h" 7 #include "core/fpdfapi/render/render_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 pitch += 31; 51 pitch += 31;
52 pitch /= 32; // quantized to number of 32-bit words. 52 pitch /= 32; // quantized to number of 32-bit words.
53 pitch *= 4; // and then back to bytes, (not just /8 in one step). 53 pitch *= 4; // and then back to bytes, (not just /8 in one step).
54 return pitch; 54 return pitch;
55 } 55 }
56 56
57 bool IsAllowedBPCValue(int bpc) { 57 bool IsAllowedBPCValue(int bpc) {
58 return bpc == 1 || bpc == 2 || bpc == 4 || bpc == 8 || bpc == 16; 58 return bpc == 1 || bpc == 2 || bpc == 4 || bpc == 8 || bpc == 16;
59 } 59 }
60 60
61 bool IsAllowedICCComponents(int nComp) {
62 return nComp == 1 || nComp == 3 || nComp == 4;
63 }
64
61 template <typename T> 65 template <typename T>
62 T ClampValue(T value, T max_value) { 66 T ClampValue(T value, T max_value) {
63 value = std::min(value, max_value); 67 value = std::min(value, max_value);
64 value = std::max<T>(0, value); 68 value = std::max<T>(0, value);
65 return value; 69 return value;
66 } 70 }
67 71
68 // Wrapper class to use with std::unique_ptr for CJPX_Decoder. 72 // Wrapper class to use with std::unique_ptr for CJPX_Decoder.
69 class JpxBitMapContext { 73 class JpxBitMapContext {
70 public: 74 public:
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 const uint8_t* src_buf, 533 const uint8_t* src_buf,
530 uint32_t src_size, 534 uint32_t src_size,
531 int width, 535 int width,
532 int height, 536 int height,
533 int nComps, 537 int nComps,
534 int bpc, 538 int bpc,
535 const CPDF_Dictionary* pParams); 539 const CPDF_Dictionary* pParams);
536 540
537 int CPDF_DIBSource::CreateDecoder() { 541 int CPDF_DIBSource::CreateDecoder() {
538 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder(); 542 const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
539 if (decoder.IsEmpty()) { 543 if (decoder.IsEmpty())
540 return 1; 544 return 1;
545
546 if (m_bDoBpcCheck && m_bpc == 0)
547 return 0;
548
549 if (decoder == "JPXDecode") {
550 LoadJpxBitmap();
551 return m_pCachedBitmap ? 1 : 0;
541 } 552 }
542 if (m_bDoBpcCheck && m_bpc == 0) { 553 if (decoder == "JBIG2Decode") {
543 return 0; 554 m_pCachedBitmap = pdfium::MakeUnique<CFX_DIBitmap>();
555 if (!m_pCachedBitmap->Create(
556 m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) {
557 m_pCachedBitmap.reset();
558 return 0;
559 }
560 m_Status = 1;
561 return 2;
544 } 562 }
563
545 const uint8_t* src_data = m_pStreamAcc->GetData(); 564 const uint8_t* src_data = m_pStreamAcc->GetData();
546 uint32_t src_size = m_pStreamAcc->GetSize(); 565 uint32_t src_size = m_pStreamAcc->GetSize();
547 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam(); 566 const CPDF_Dictionary* pParams = m_pStreamAcc->GetImageParam();
548 if (decoder == "CCITTFaxDecode") { 567 if (decoder == "CCITTFaxDecode") {
549 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width, 568 m_pDecoder.reset(FPDFAPI_CreateFaxDecoder(src_data, src_size, m_Width,
550 m_Height, pParams)); 569 m_Height, pParams));
570 } else if (decoder == "FlateDecode") {
571 m_pDecoder.reset(FPDFAPI_CreateFlateDecoder(
572 src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams));
573 } else if (decoder == "RunLengthDecode") {
574 m_pDecoder.reset(CPDF_ModuleMgr::Get()
575 ->GetCodecModule()
576 ->GetBasicModule()
577 ->CreateRunLengthDecoder(src_data, src_size, m_Width,
578 m_Height, m_nComponents,
579 m_bpc));
551 } else if (decoder == "DCTDecode") { 580 } else if (decoder == "DCTDecode") {
552 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( 581 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
553 src_data, src_size, m_Width, m_Height, m_nComponents, 582 src_data, src_size, m_Width, m_Height, m_nComponents,
554 !pParams || pParams->GetIntegerFor("ColorTransform", 1))); 583 !pParams || pParams->GetIntegerFor("ColorTransform", 1)));
555 if (!m_pDecoder) { 584 if (!m_pDecoder) {
556 bool bTransform = false; 585 bool bTransform = false;
557 int comps; 586 int comps;
558 int bpc; 587 int bpc;
559 CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule(); 588 CCodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule();
560 if (pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps, 589 if (pJpegModule->LoadInfo(src_data, src_size, &m_Width, &m_Height, &comps,
561 &bpc, &bTransform)) { 590 &bpc, &bTransform)) {
562 if (m_nComponents != static_cast<uint32_t>(comps)) { 591 if (m_nComponents != static_cast<uint32_t>(comps)) {
563 FX_Free(m_pCompData); 592 FX_Free(m_pCompData);
564 m_pCompData = nullptr; 593 m_pCompData = nullptr;
565 m_nComponents = static_cast<uint32_t>(comps); 594 m_nComponents = static_cast<uint32_t>(comps);
566 if (m_pColorSpace && 595 if (m_pColorSpace) {
567 m_pColorSpace->CountComponents() != m_nComponents) { 596 switch (m_Family) {
568 return 0; 597 case PDFCS_DEVICEGRAY:
598 case PDFCS_DEVICERGB:
599 case PDFCS_DEVICECMYK: {
600 uint32_t dwMinComps = ComponentsForFamily(m_Family);
601 if (m_pColorSpace->CountComponents() < dwMinComps ||
602 m_nComponents < dwMinComps) {
603 return 0;
604 }
605 break;
606 }
607 case PDFCS_LAB: {
608 if (m_nComponents != 3 || m_pColorSpace->CountComponents() < 3)
609 return 0;
610 break;
611 }
612 case PDFCS_ICCBASED: {
613 if (!IsAllowedICCComponents(m_nComponents) ||
614 !IsAllowedICCComponents(m_pColorSpace->CountComponents()) ||
615 m_pColorSpace->CountComponents() < m_nComponents) {
616 return 0;
617 }
618 break;
619 }
620 default: {
621 if (m_pColorSpace->CountComponents() != m_nComponents)
622 return 0;
623 break;
624 }
625 }
626 } else {
627 if (m_Family == PDFCS_LAB && m_nComponents != 3)
628 return 0;
569 } 629 }
570 if (m_Family == PDFCS_LAB && m_nComponents != 3)
571 return 0;
572 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey); 630 m_pCompData = GetDecodeAndMaskArray(m_bDefaultDecode, m_bColorKey);
573 if (!m_pCompData) 631 if (!m_pCompData)
574 return 0; 632 return 0;
575 } 633 }
576 m_bpc = bpc; 634 m_bpc = bpc;
577 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder( 635 m_pDecoder.reset(CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
578 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform)); 636 src_data, src_size, m_Width, m_Height, m_nComponents, bTransform));
579 } 637 }
580 } 638 }
581 } else if (decoder == "FlateDecode") {
582 m_pDecoder.reset(FPDFAPI_CreateFlateDecoder(
583 src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams));
584 } else if (decoder == "JPXDecode") {
585 LoadJpxBitmap();
586 return m_pCachedBitmap ? 1 : 0;
587 } else if (decoder == "JBIG2Decode") {
588 m_pCachedBitmap.reset(new CFX_DIBitmap);
589 if (!m_pCachedBitmap->Create(
590 m_Width, m_Height, m_bImageMask ? FXDIB_1bppMask : FXDIB_1bppRgb)) {
591 m_pCachedBitmap.reset();
592 return 0;
593 }
594 m_Status = 1;
595 return 2;
596 } else if (decoder == "RunLengthDecode") {
597 m_pDecoder.reset(CPDF_ModuleMgr::Get()
598 ->GetCodecModule()
599 ->GetBasicModule()
600 ->CreateRunLengthDecoder(src_data, src_size, m_Width,
601 m_Height, m_nComponents,
602 m_bpc));
603 } 639 }
604 if (!m_pDecoder) 640 if (!m_pDecoder)
605 return 0; 641 return 0;
606 642
607 FX_SAFE_UINT32 requested_pitch = 643 FX_SAFE_UINT32 requested_pitch =
608 CalculatePitch8(m_bpc, m_nComponents, m_Width); 644 CalculatePitch8(m_bpc, m_nComponents, m_Width);
609 if (!requested_pitch.IsValid()) 645 if (!requested_pitch.IsValid())
610 return 0; 646 return 0;
611 FX_SAFE_UINT32 provided_pitch = CalculatePitch8( 647 FX_SAFE_UINT32 provided_pitch = CalculatePitch8(
612 m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth()); 648 m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth());
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 IFX_Pause* pPause) { 1586 IFX_Pause* pPause) {
1551 return LoadHandle->Continue(pPause); 1587 return LoadHandle->Continue(pPause);
1552 } 1588 }
1553 1589
1554 CPDF_ImageLoader::~CPDF_ImageLoader() { 1590 CPDF_ImageLoader::~CPDF_ImageLoader() {
1555 if (!m_bCached) { 1591 if (!m_bCached) {
1556 delete m_pBitmap; 1592 delete m_pBitmap;
1557 delete m_pMask; 1593 delete m_pMask;
1558 } 1594 }
1559 } 1595 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/fpdf_page_colors.cpp ('k') | core/fxcodec/fx_codec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698