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

Unified Diff: core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp

Issue 497733005: Add GetValidBpc() check in CPDF_DIBSource::GetScanLine (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..35faaf26488df104babf93e25cafaf97a443ea2e 100644
--- a/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
+++ b/core/src/fpdfapi/fpdf_render/fpdf_render_loadimage.cpp
@@ -1047,8 +1047,16 @@ FX_LPBYTE CPDF_DIBSource::GetBuffer() const
}
FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
{
- FX_DWORD src_pitch = (m_Width * m_bpc * m_nComponents + 7) / 8;
+ FX_DWORD bpc = GetValidBpc();
Tom Sepez 2014/08/25 17:30:21 Do we need to check for bcp == 0 error case?
Bo Xu 2014/08/25 18:27:51 Done.
+ FX_SAFE_DWORD src_pitch = m_Width;
+ src_pitch *= bpc;
+ src_pitch *= m_nComponents;
+ src_pitch += 7;
+ src_pitch /= 8;
+ if (!src_pitch.IsValid())
+ return NULL;
FX_LPCBYTE pSrcLine = NULL;
+
Tom Sepez 2014/08/25 17:30:21 nit: stray blank line here. This codebase seems h
Bo Xu 2014/08/25 18:27:51 Agree, no blank line seems better.
Bo Xu 2014/08/25 18:27:51 Done.
if (m_pCachedBitmap) {
if (line >= m_pCachedBitmap->GetHeight()) {
line = m_pCachedBitmap->GetHeight() - 1;
@@ -1057,8 +1065,8 @@ FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
} else if (m_pDecoder) {
pSrcLine = m_pDecoder->GetScanline(line);
} else {
- if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch) {
- pSrcLine = m_pStreamAcc->GetData() + line * src_pitch;
+ if (m_pStreamAcc->GetSize() >= (line + 1) * src_pitch.ValueOrDie()) {
Tom Sepez 2014/08/25 17:30:21 nit: it may be better to move src_pitch.ValueOrDie
Bo Xu 2014/08/25 18:27:51 Done.
+ pSrcLine = m_pStreamAcc->GetData() + line * src_pitch.ValueOrDie();
}
}
if (pSrcLine == NULL) {
@@ -1066,9 +1074,9 @@ FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
FXSYS_memset8(pLineBuf, 0xff, m_Pitch);
return pLineBuf;
}
- if (m_bpc * m_nComponents == 1) {
+ if (bpc * m_nComponents == 1) {
if (m_bImageMask && m_bDefaultDecode) {
- for (FX_DWORD i = 0; i < src_pitch; i ++) {
+ for (FX_DWORD i = 0; i < src_pitch.ValueOrDie(); i++) {
m_pLineBuf[i] = ~pSrcLine[i];
}
} else if (m_bColorKey) {
@@ -1094,21 +1102,21 @@ FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
}
return m_pMaskedLine;
} else {
- FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch);
+ FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch.ValueOrDie());
}
return m_pLineBuf;
}
- if (m_bpc * m_nComponents <= 8) {
- if (m_bpc == 8) {
- FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch);
+ if (bpc * m_nComponents <= 8) {
+ if (bpc == 8) {
+ FXSYS_memcpy32(m_pLineBuf, pSrcLine, src_pitch.ValueOrDie());
} else {
int src_bit_pos = 0;
for (int col = 0; col < m_Width; col ++) {
int color_index = 0;
for (FX_DWORD color = 0; color < m_nComponents; color ++) {
- int data = _GetBits8(pSrcLine, src_bit_pos, m_bpc);
- color_index |= data << (color * m_bpc);
- src_bit_pos += m_bpc;
+ int data = _GetBits8(pSrcLine, src_bit_pos, bpc);
+ color_index |= data << (color * bpc);
+ src_bit_pos += bpc;
}
m_pLineBuf[col] = color_index;
}
@@ -1135,7 +1143,7 @@ FX_LPCBYTE CPDF_DIBSource::GetScanline(int line) const
return m_pLineBuf;
}
if (m_bColorKey) {
- if (m_nComponents == 3 && m_bpc == 8) {
+ if (m_nComponents == 3 && bpc == 8) {
FX_LPBYTE alpha_channel = m_pMaskedLine + 3;
for (int col = 0; col < m_Width; col ++) {
FX_LPCBYTE pPixel = pSrcLine + col * 3;
« 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