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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
diff --git a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
index 77d595dd88356a1193e1006fd188c919ed41e186..3d44f5c0018bcfef32d9f76eff95fd0b562c79c5 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -560,6 +560,7 @@ ICodec_ScanlineDecoder* FPDFAPI_CreateFlateDecoder(FX_LPCBYTE src_buf, FX_DWORD
int nComps, int bpc, const CPDF_Dictionary* pParams);
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
{
+ 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.
const CFX_ByteString& decoder = m_pStreamAcc->GetImageDecoder();
if (decoder.IsEmpty()) {
return 1;
@@ -574,9 +575,9 @@ int CPDF_DIBSource::CreateDecoder()
m_nComponents, pParams ? pParams->GetInteger(FX_BSTR("ColorTransform"), 1) : 1);
if (NULL == m_pDecoder) {
FX_BOOL bTransform = FALSE;
- int comps, bpc;
+ int comps;
ICodec_JpegModule* pJpegModule = CPDF_ModuleMgr::Get()->GetJpegModule();
- if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, bpc, bTransform)) {
+ if (pJpegModule->LoadInfo(src_data, src_size, m_Width, m_Height, comps, (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.
m_nComponents = comps;
m_bpc = bpc;
m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(src_data, src_size, m_Width, m_Height,
@@ -584,7 +585,7 @@ int CPDF_DIBSource::CreateDecoder()
}
}
} else if (decoder == FX_BSTRC("FlateDecode")) {
- m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc, pParams);
+ m_pDecoder = FPDFAPI_CreateFlateDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, bpc, pParams);
} else if (decoder == FX_BSTRC("JPXDecode")) {
LoadJpxBitmap();
return m_pCachedBitmap != NULL ? 1 : 0;
@@ -601,9 +602,23 @@ int CPDF_DIBSource::CreateDecoder()
m_pDecoder = CPDF_ModuleMgr::Get()->GetCodecModule()->GetBasicModule()->CreateRunLengthDecoder(src_data, src_size, m_Width, m_Height, m_nComponents, m_bpc);
}
if (m_pDecoder) {
- int requested_pitch = (m_Width * m_nComponents * m_bpc + 7) / 8;
- int provided_pitch = (m_pDecoder->GetWidth() * m_pDecoder->CountComps() * m_pDecoder->GetBPC() + 7) / 8;
- if (provided_pitch < requested_pitch) {
+ FX_SAFE_DWORD requested_pitch = bpc;
+ requested_pitch *= m_nComponents;
+ requested_pitch *= m_Width;
+ requested_pitch += 7;
+ requested_pitch /= 8;
+ if (!requested_pitch.IsValid()) {
+ return 1;
+ }
+ FX_SAFE_DWORD provided_pitch = m_pDecoder->GetBPC();
+ provided_pitch *= m_pDecoder->CountComps();
+ provided_pitch *= m_pDecoder->GetWidth();
+ provided_pitch += 7;
+ provided_pitch /= 8;
+ if (!provided_pitch.IsValid()) {
+ return 1;
+ }
+ if (provided_pitch.ValueOrDie() < requested_pitch.ValueOrDie()) {
return 0;
}
return 1;
« 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