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

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

Issue 1432073003: Fix CalculatePitch32() issues. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 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 | « 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 <vector> 7 #include <vector>
8 8
9 #include "../../../include/fpdfapi/fpdf_module.h" 9 #include "../../../include/fpdfapi/fpdf_module.h"
10 #include "../../../include/fpdfapi/fpdf_pageobj.h" 10 #include "../../../include/fpdfapi/fpdf_pageobj.h"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 if (nbits == 1) { 32 if (nbits == 1) {
33 return (byte >> (7 - bitpos % 8)) & 0x01; 33 return (byte >> (7 - bitpos % 8)) & 0x01;
34 } 34 }
35 if (nbits == 16) { 35 if (nbits == 16) {
36 return byte * 256 + pData[bitpos / 8 + 1]; 36 return byte * 256 + pData[bitpos / 8 + 1];
37 } 37 }
38 return 0; 38 return 0;
39 } 39 }
40 40
41 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc, 41 FX_SAFE_DWORD CalculatePitch8(FX_DWORD bpc, FX_DWORD components, int width) {
42 FX_DWORD components,
43 int width,
44 int height) {
45 FX_SAFE_DWORD pitch = bpc; 42 FX_SAFE_DWORD pitch = bpc;
46 pitch *= components; 43 pitch *= components;
47 pitch *= width; 44 pitch *= width;
48 pitch += 7; 45 pitch += 7;
49 pitch /= 8; 46 pitch /= 8;
50 pitch *= height;
51 return pitch; 47 return pitch;
52 } 48 }
53 49
54 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) { 50 FX_SAFE_DWORD CalculatePitch32(int bpp, int width) {
55 FX_SAFE_DWORD pitch = bpp; 51 FX_SAFE_DWORD pitch = bpp;
56 pitch *= width; 52 pitch *= width;
57 pitch += 31; 53 pitch += 31;
58 pitch /= 8; 54 pitch /= 32; // quantized to number of 32-bit words.
55 pitch *= 4; // and then back to bytes, (not just /8 in one step).
59 return pitch; 56 return pitch;
60 } 57 }
61 58
62 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder. 59 // Wrapper class to use with nonstd::unique_ptr for CJPX_Decoder.
63 class JpxBitMapContext { 60 class JpxBitMapContext {
64 public: 61 public:
65 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module) 62 explicit JpxBitMapContext(ICodec_JpxModule* jpx_module)
66 : jpx_module_(jpx_module), decoder_(nullptr) {} 63 : jpx_module_(jpx_module), decoder_(nullptr) {}
67 64
68 ~JpxBitMapContext() { 65 ~JpxBitMapContext() {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 222 }
226 m_GroupFamily = GroupFamily; 223 m_GroupFamily = GroupFamily;
227 m_bLoadMask = bLoadMask; 224 m_bLoadMask = bLoadMask;
228 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 225 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
229 pPageResources)) { 226 pPageResources)) {
230 return FALSE; 227 return FALSE;
231 } 228 }
232 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 229 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
233 return FALSE; 230 return FALSE;
234 } 231 }
235 FX_SAFE_DWORD src_pitch = 232 FX_SAFE_DWORD src_size =
236 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); 233 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
237 if (!src_pitch.IsValid()) { 234 if (!src_size.IsValid()) {
238 return FALSE; 235 return FALSE;
239 } 236 }
240 m_pStreamAcc = new CPDF_StreamAcc; 237 m_pStreamAcc = new CPDF_StreamAcc;
241 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); 238 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE);
242 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 239 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) {
243 return FALSE; 240 return FALSE;
244 } 241 }
245 if (!CreateDecoder()) { 242 if (!CreateDecoder()) {
246 return FALSE; 243 return FALSE;
247 } 244 }
248 if (m_bImageMask) { 245 if (m_bImageMask) {
249 m_bpp = 1; 246 m_bpp = 1;
250 m_bpc = 1; 247 m_bpc = 1;
251 m_nComponents = 1; 248 m_nComponents = 1;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 342 }
346 m_GroupFamily = GroupFamily; 343 m_GroupFamily = GroupFamily;
347 m_bLoadMask = bLoadMask; 344 m_bLoadMask = bLoadMask;
348 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources, 345 if (!LoadColorInfo(m_pStream->GetObjNum() != 0 ? NULL : pFormResources,
349 pPageResources)) { 346 pPageResources)) {
350 return 0; 347 return 0;
351 } 348 }
352 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) { 349 if (m_bDoBpcCheck && (m_bpc == 0 || m_nComponents == 0)) {
353 return 0; 350 return 0;
354 } 351 }
355 FX_SAFE_DWORD src_pitch = 352 FX_SAFE_DWORD src_size =
356 CalculatePitch8(m_bpc, m_nComponents, m_Width, m_Height); 353 CalculatePitch8(m_bpc, m_nComponents, m_Width) * m_Height;
357 if (!src_pitch.IsValid()) { 354 if (!src_size.IsValid()) {
358 return 0; 355 return 0;
359 } 356 }
360 m_pStreamAcc = new CPDF_StreamAcc; 357 m_pStreamAcc = new CPDF_StreamAcc;
361 m_pStreamAcc->LoadAllData(pStream, FALSE, src_pitch.ValueOrDie(), TRUE); 358 m_pStreamAcc->LoadAllData(pStream, FALSE, src_size.ValueOrDie(), TRUE);
362 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) { 359 if (m_pStreamAcc->GetSize() == 0 || m_pStreamAcc->GetData() == NULL) {
363 return 0; 360 return 0;
364 } 361 }
365 int ret = CreateDecoder(); 362 int ret = CreateDecoder();
366 if (ret != 1) { 363 if (ret != 1) {
367 if (!ret) { 364 if (!ret) {
368 return ret; 365 return ret;
369 } 366 }
370 if (!ContinueToLoadMask()) { 367 if (!ContinueToLoadMask()) {
371 return 0; 368 return 0;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 m_pDecoder = CPDF_ModuleMgr::Get() 654 m_pDecoder = CPDF_ModuleMgr::Get()
658 ->GetCodecModule() 655 ->GetCodecModule()
659 ->GetBasicModule() 656 ->GetBasicModule()
660 ->CreateRunLengthDecoder(src_data, src_size, m_Width, 657 ->CreateRunLengthDecoder(src_data, src_size, m_Width,
661 m_Height, m_nComponents, m_bpc); 658 m_Height, m_nComponents, m_bpc);
662 } 659 }
663 if (!m_pDecoder) 660 if (!m_pDecoder)
664 return 0; 661 return 0;
665 662
666 FX_SAFE_DWORD requested_pitch = 663 FX_SAFE_DWORD requested_pitch =
667 CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); 664 CalculatePitch8(m_bpc, m_nComponents, m_Width);
668 if (!requested_pitch.IsValid()) { 665 if (!requested_pitch.IsValid()) {
669 return 0; 666 return 0;
670 } 667 }
671 FX_SAFE_DWORD provided_pitch = 668 FX_SAFE_DWORD provided_pitch = CalculatePitch8(
672 CalculatePitch8(m_pDecoder->GetBPC(), m_pDecoder->CountComps(), 669 m_pDecoder->GetBPC(), m_pDecoder->CountComps(), m_pDecoder->GetWidth());
673 m_pDecoder->GetWidth(), 1);
674 if (!provided_pitch.IsValid()) { 670 if (!provided_pitch.IsValid()) {
675 return 0; 671 return 0;
676 } 672 }
677 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) { 673 if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
678 return 0; 674 return 0;
679 } 675 }
680 return 1; 676 return 1;
681 } 677 }
682 void CPDF_DIBSource::LoadJpxBitmap() { 678 void CPDF_DIBSource::LoadJpxBitmap() {
683 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule(); 679 ICodec_JpxModule* pJpxModule = CPDF_ModuleMgr::Get()->GetJpxModule();
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 uint8_t* CPDF_DIBSource::GetBuffer() const { 1076 uint8_t* CPDF_DIBSource::GetBuffer() const {
1081 if (m_pCachedBitmap) { 1077 if (m_pCachedBitmap) {
1082 return m_pCachedBitmap->GetBuffer(); 1078 return m_pCachedBitmap->GetBuffer();
1083 } 1079 }
1084 return NULL; 1080 return NULL;
1085 } 1081 }
1086 const uint8_t* CPDF_DIBSource::GetScanline(int line) const { 1082 const uint8_t* CPDF_DIBSource::GetScanline(int line) const {
1087 if (m_bpc == 0) { 1083 if (m_bpc == 0) {
1088 return NULL; 1084 return NULL;
1089 } 1085 }
1090 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); 1086 FX_SAFE_DWORD src_pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
1091 if (!src_pitch.IsValid()) 1087 if (!src_pitch.IsValid())
1092 return NULL; 1088 return NULL;
1093 FX_DWORD src_pitch_value = src_pitch.ValueOrDie(); 1089 FX_DWORD src_pitch_value = src_pitch.ValueOrDie();
1094 const uint8_t* pSrcLine = NULL; 1090 const uint8_t* pSrcLine = NULL;
1095 if (m_pCachedBitmap) { 1091 if (m_pCachedBitmap) {
1096 if (line >= m_pCachedBitmap->GetHeight()) { 1092 if (line >= m_pCachedBitmap->GetHeight()) {
1097 line = m_pCachedBitmap->GetHeight() - 1; 1093 line = m_pCachedBitmap->GetHeight() - 1;
1098 } 1094 }
1099 pSrcLine = m_pCachedBitmap->GetScanline(line); 1095 pSrcLine = m_pCachedBitmap->GetScanline(line);
1100 } else if (m_pDecoder) { 1096 } else if (m_pDecoder) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 int dest_width, 1222 int dest_width,
1227 FX_BOOL bFlipX, 1223 FX_BOOL bFlipX,
1228 int clip_left, 1224 int clip_left,
1229 int clip_width) const { 1225 int clip_width) const {
1230 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 || 1226 if (line < 0 || !dest_scan || dest_bpp <= 0 || dest_width <= 0 ||
1231 clip_left < 0 || clip_width <= 0) { 1227 clip_left < 0 || clip_width <= 0) {
1232 return; 1228 return;
1233 } 1229 }
1234 1230
1235 FX_DWORD src_width = m_Width; 1231 FX_DWORD src_width = m_Width;
1236 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width, 1); 1232 FX_SAFE_DWORD pitch = CalculatePitch8(m_bpc, m_nComponents, m_Width);
1237 if (!pitch.IsValid()) 1233 if (!pitch.IsValid())
1238 return; 1234 return;
1239 1235
1240 const uint8_t* pSrcLine = nullptr; 1236 const uint8_t* pSrcLine = nullptr;
1241 if (m_pCachedBitmap) { 1237 if (m_pCachedBitmap) {
1242 pSrcLine = m_pCachedBitmap->GetScanline(line); 1238 pSrcLine = m_pCachedBitmap->GetScanline(line);
1243 } else if (m_pDecoder) { 1239 } else if (m_pDecoder) {
1244 pSrcLine = m_pDecoder->GetScanline(line); 1240 pSrcLine = m_pDecoder->GetScanline(line);
1245 } else { 1241 } else {
1246 FX_DWORD src_pitch = pitch.ValueOrDie(); 1242 FX_DWORD src_pitch = pitch.ValueOrDie();
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1640 }
1645 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) { 1641 FX_BOOL CPDF_ImageLoader::Continue(void* LoadHandle, IFX_Pause* pPause) {
1646 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause); 1642 return ((CPDF_ProgressiveImageLoaderHandle*)LoadHandle)->Continue(pPause);
1647 } 1643 }
1648 CPDF_ImageLoader::~CPDF_ImageLoader() { 1644 CPDF_ImageLoader::~CPDF_ImageLoader() {
1649 if (!m_bCached) { 1645 if (!m_bCached) {
1650 delete m_pBitmap; 1646 delete m_pBitmap;
1651 delete m_pMask; 1647 delete m_pMask;
1652 } 1648 }
1653 } 1649 }
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