summaryrefslogtreecommitdiff
path: root/core/fxcodec
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2018-01-17 21:30:07 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-01-17 21:30:07 +0000
commit2993b758326c4f7f91cc6d6840bb1efde7642623 (patch)
tree44a4ad90a162c322c3f9630fac221e940f23b39b /core/fxcodec
parent4c431bab10ab8ec3681f88be4f62002de069eeb6 (diff)
downloadpdfium-2993b758326c4f7f91cc6d6840bb1efde7642623.tar.xz
Move remaining jpeg error handling up a level
This moves the setjmps needed for handling fatal errors in the jpeg library up a level to be in line with how other instances of this are being modified. This additionally reduces the number of times that setjmp needs to be called and documents why it is occurring. This covers the Start and ReadScanLine methods. It also adds in setting the error member, which had been missed in previous CLs. BUG=pdfium:986 Change-Id: I7db87288ffe0ee8b29899d97035c30ad812da76a Reviewed-on: https://pdfium-review.googlesource.com/23117 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'core/fxcodec')
-rw-r--r--core/fxcodec/codec/fx_codec_jpeg.cpp7
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp13
2 files changed, 14 insertions, 6 deletions
diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp
index f7cf291bbf..cf501a99d1 100644
--- a/core/fxcodec/codec/fx_codec_jpeg.cpp
+++ b/core/fxcodec/codec/fx_codec_jpeg.cpp
@@ -417,7 +417,7 @@ CJpegContext::~CJpegContext() {
}
std::unique_ptr<CCodec_JpegModule::Context> CCodec_JpegModule::Start() {
- // Use ordinary pointer until past the fear of a longjump.
+ // Use ordinary pointer until past the possibility of a longjump.
auto* pContext = new CJpegContext();
if (setjmp(pContext->m_JumpMark) == -1)
return nullptr;
@@ -486,10 +486,7 @@ bool CCodec_JpegModule::StartScanline(Context* pContext, int down_scale) {
bool CCodec_JpegModule::ReadScanline(Context* pContext,
unsigned char* dest_buf) {
auto* ctx = static_cast<CJpegContext*>(pContext);
- if (setjmp(ctx->m_JumpMark) == -1)
- return false;
-
- int nlines = jpeg_read_scanlines(&ctx->m_Info, &dest_buf, 1);
+ unsigned int nlines = jpeg_read_scanlines(&ctx->m_Info, &dest_buf, 1);
return nlines == 1;
}
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index c3005bca95..36e22e9f85 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -1879,8 +1879,11 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::StartDecode(
GetDownScale(down_scale);
// Setting jump marker before calling StartScanLine, since a longjmp to
// the marker indicates a fatal error.
- if (setjmp(*m_pJpegContext->GetJumpMark()) == -1)
+ if (setjmp(*m_pJpegContext->GetJumpMark()) == -1) {
+ m_pJpegContext.reset();
+ m_status = FXCODEC_STATUS_ERROR;
return FXCODEC_STATUS_ERROR;
+ }
CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
bool startStatus =
@@ -2023,6 +2026,14 @@ FXCODEC_STATUS CCodec_ProgressiveDecoder::ContinueDecode() {
switch (m_imagType) {
case FXCODEC_IMAGE_JPG: {
CCodec_JpegModule* pJpegModule = m_pCodecMgr->GetJpegModule();
+ // Setting jump marker before calling ReadScanLine, since a longjmp to
+ // the marker indicates a fatal error.
+ if (setjmp(*m_pJpegContext->GetJumpMark()) == -1) {
+ m_pJpegContext.reset();
+ m_status = FXCODEC_STATUS_ERROR;
+ return FXCODEC_STATUS_ERROR;
+ }
+
while (true) {
bool readRes =
pJpegModule->ReadScanline(m_pJpegContext.get(), m_pDecodeBuf);