From 4c431bab10ab8ec3681f88be4f62002de069eeb6 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 17 Jan 2018 21:15:57 +0000 Subject: Move jpeg header read error handling up a level This move the setjmp 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 occuring. BUG=pdfium:986 Change-Id: Ia57821e1ce65aae811618effb3f2fa6256e1ab8c Reviewed-on: https://pdfium-review.googlesource.com/23115 Reviewed-by: dsinclair Commit-Queue: Ryan Harrison --- core/fxcodec/codec/fx_codec_jpeg.cpp | 3 --- core/fxcodec/codec/fx_codec_progress.cpp | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/fxcodec/codec/fx_codec_jpeg.cpp b/core/fxcodec/codec/fx_codec_jpeg.cpp index 4d4adfd817..f7cf291bbf 100644 --- a/core/fxcodec/codec/fx_codec_jpeg.cpp +++ b/core/fxcodec/codec/fx_codec_jpeg.cpp @@ -459,9 +459,6 @@ int CCodec_JpegModule::ReadHeader(Context* pContext, int* nComps) { #endif // PDF_ENABLE_XFA auto* ctx = static_cast(pContext); - if (setjmp(ctx->m_JumpMark) == -1) - return 1; - int ret = jpeg_read_header(&ctx->m_Info, true); if (ret == JPEG_SUSPENDED) return 2; diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp index c9436186ab..c3005bca95 100644 --- a/core/fxcodec/codec/fx_codec_progress.cpp +++ b/core/fxcodec/codec/fx_codec_progress.cpp @@ -1105,6 +1105,14 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType, } m_offSet += size; pJpegModule->Input(m_pJpegContext.get(), m_pSrcBuf, size); + // Setting jump marker before calling ReadHeader, since a longjmp to + // the marker indicates a fatal error. + if (setjmp(*m_pJpegContext->GetJumpMark()) == -1) { + m_pJpegContext.reset(); + m_status = FXCODEC_STATUS_ERR_FORMAT; + return false; + } + int32_t readResult = pJpegModule->ReadHeader(m_pJpegContext.get(), &m_SrcWidth, &m_SrcHeight, &m_SrcComponents, pAttribute); -- cgit v1.2.3