From 61f66c9be2abf4f2a5f8bc299ad6e1900c63dbc3 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 27 Apr 2018 16:54:28 +0000 Subject: Add CJBig2_Image::IsValidImageSize() helper method. Change-Id: Ic2acd6f03b9b2e52b3d94d7579d5dc36c8e62c96 Reviewed-on: https://pdfium-review.googlesource.com/31530 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- core/fxcodec/jbig2/JBig2_Context.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'core/fxcodec/jbig2/JBig2_Context.cpp') diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index c8095c8448..a3c6f587b4 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -637,10 +637,8 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { m_pStream->readShortInteger(&wFlags) != 0) { return JBIG2_ERROR_TOO_SHORT; } - if (ri.width <= 0 || ri.width > JBIG2_MAX_IMAGE_SIZE || ri.height <= 0 || - ri.height > JBIG2_MAX_IMAGE_SIZE) { + if (!CJBig2_Image::IsValidImageSize(ri.width, ri.height)) return JBIG2_ERROR_FATAL; - } auto pTRD = pdfium::MakeUnique(); pTRD->SBW = ri.width; @@ -995,15 +993,11 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, return JBIG2_ERROR_TOO_SHORT; } - if (pHRD->HGW == 0 || pHRD->HGW > JBIG2_MAX_IMAGE_SIZE || pHRD->HGH == 0 || - pHRD->HGH > JBIG2_MAX_IMAGE_SIZE) { + if (!CJBig2_Image::IsValidImageSize(pHRD->HGW, pHRD->HGH)) return JBIG2_ERROR_FATAL; - } - if (ri.width <= 0 || ri.width > JBIG2_MAX_IMAGE_SIZE || ri.height <= 0 || - ri.height > JBIG2_MAX_IMAGE_SIZE) { + if (!CJBig2_Image::IsValidImageSize(ri.width, ri.height)) return JBIG2_ERROR_FATAL; - } pHRD->HBW = ri.width; pHRD->HBH = ri.height; @@ -1169,10 +1163,8 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { m_pStream->read1Byte(&cFlags) != 0) { return JBIG2_ERROR_TOO_SHORT; } - if (ri.width <= 0 || ri.width > JBIG2_MAX_IMAGE_SIZE || ri.height <= 0 || - ri.height > JBIG2_MAX_IMAGE_SIZE) { + if (!CJBig2_Image::IsValidImageSize(ri.width, ri.height)) return JBIG2_ERROR_FATAL; - } auto pGRRD = pdfium::MakeUnique(); pGRRD->GRW = ri.width; -- cgit v1.2.3