From 0e46ce2948c8b45e9e5adcf6c4cb27620d5ba8ae Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Tue, 2 Dec 2014 18:40:49 -0800 Subject: Fix blank page issues caused by too strict check Before this fix, PDF parser aborts the parsering process when detecting an error. For this case, PDF parser just gives up parsering when it detects that the length of image stream is incorrect. The solution to this case is to find the tag "endstream" and "endobj" to calculate the length rather than aborting the parsering process. BUG=433339 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/743263002 (cherry picked from commit ef619d0562b39f30943cfdc4985a0df233d00e42) Review URL: https://codereview.chromium.org/776833002 --- core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'core') diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index e9c0fdd227..85992a83e3 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2435,16 +2435,13 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT pContext->m_DataStart = m_Pos; } - base::CheckedNumeric pos = m_Pos; - pos += len; - if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { - m_Pos = pos.ValueOrDie(); - } else { - return NULL; - } - CPDF_CryptoHandler* pCryptoHandler = objnum == (FX_DWORD)m_MetadataObjnum ? NULL : m_pCryptoHandler; if (pCryptoHandler == NULL) { + base::CheckedNumeric pos = m_Pos; + pos += len; + if (pos.IsValid() && pos.ValueOrDie() < m_FileLen) { + m_Pos = pos.ValueOrDie(); + } GetNextWord(); if (m_WordSize < 9 || FXSYS_memcmp32(m_WordBuffer, "endstream", 9)) { m_Pos = StreamStartPos; @@ -2475,8 +2472,8 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict, PARSE_CONTEXT } } } + m_Pos = StreamStartPos; } - m_Pos = StreamStartPos; CPDF_Stream* pStream; #if defined(_FPDFAPI_MINI_) && !defined(_FXCORE_FEATURE_ALL_) pStream = FX_NEW CPDF_Stream(m_pFileAccess, pCryptoHandler, m_HeaderOffset + m_Pos, len, pDict, gennum); -- cgit v1.2.3