From 2993b758326c4f7f91cc6d6840bb1efde7642623 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 17 Jan 2018 21:30:07 +0000 Subject: 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 Commit-Queue: Ryan Harrison --- core/fxcodec/codec/fx_codec_jpeg.cpp | 7 ++----- core/fxcodec/codec/fx_codec_progress.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'core') 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::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(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); -- cgit v1.2.3