summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-08 14:16:01 -0700
committerLei Zhang <thestig@chromium.org>2015-10-08 14:16:01 -0700
commit89b71f7a9b25bc752e9e019f869842169c325480 (patch)
tree9df4240d1ed7164961124b57b51ab5f82de1f2d1
parentf7f0f8a106f3c792469368bd75fa2d8e4a954155 (diff)
downloadpdfium-89b71f7a9b25bc752e9e019f869842169c325480.tar.xz
Merge to M47: Relax the check on 0 length streams.
CPDF_SyntaxParser::ReadStream() originally created stream objects when the length is 0. Commit 2526930 tightened the constraint and returned NULL. This has some adverse affects, as seen in Chromium's print preview of PDFs. Instead, relax the constraint a little so when the length is 0, return a CPDF_Stream with NULL data and size 0. BUG=531835 TBR=tsepez@chromium.org Review URL: https://codereview.chromium.org/1394743002 . (cherry picked from commit 4fa0e27ba39f49ba92fb4c160ab836a6f1dd2893) Review URL: https://codereview.chromium.org/1391183005 .
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 984e08d882..a94e5bb01d 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -2521,28 +2521,31 @@ CPDF_Stream* CPDF_SyntaxParser::ReadStream(CPDF_Dictionary* pDict,
len -= 1;
}
}
- if (len <= 0) {
+ if (len < 0) {
return nullptr;
}
pDict->SetAtInteger(FX_BSTRC("Length"), len);
}
m_Pos = streamStartPos;
}
- if (len <= 0) {
+ if (len < 0) {
return nullptr;
}
- uint8_t* pData = FX_Alloc(uint8_t, len);
- ReadBlock(pData, len);
- if (pCryptoHandler) {
- CFX_BinaryBuf dest_buf;
- dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len));
- void* context = pCryptoHandler->DecryptStart(objnum, gennum);
- pCryptoHandler->DecryptStream(context, pData, len, dest_buf);
- pCryptoHandler->DecryptFinish(context, dest_buf);
- FX_Free(pData);
- pData = dest_buf.GetBuffer();
- len = dest_buf.GetSize();
- dest_buf.DetachBuffer();
+ uint8_t* pData = nullptr;
+ if (len > 0) {
+ pData = FX_Alloc(uint8_t, len);
+ ReadBlock(pData, len);
+ if (pCryptoHandler) {
+ CFX_BinaryBuf dest_buf;
+ dest_buf.EstimateSize(pCryptoHandler->DecryptGetSize(len));
+ void* context = pCryptoHandler->DecryptStart(objnum, gennum);
+ pCryptoHandler->DecryptStream(context, pData, len, dest_buf);
+ pCryptoHandler->DecryptFinish(context, dest_buf);
+ FX_Free(pData);
+ pData = dest_buf.GetBuffer();
+ len = dest_buf.GetSize();
+ dest_buf.DetachBuffer();
+ }
}
CPDF_Stream* pStream = new CPDF_Stream(pData, len, pDict);
if (pContext) {