From 0a039136e8e46ddbcb45b55e92d80ddb2ddfc2c2 Mon Sep 17 00:00:00 2001 From: Wei-Ta Chen Date: Thu, 3 Nov 2011 10:59:01 -0700 Subject: Fix an OOM issue in mosaic blending. Set two limits on when we will do mosaic blending. 1) mosaic_width * mosaic_height < (5 * frame_width) * (2 * frame_height) 2) mosaic_height < 2.5 * frame_height The latter limit rejects blending for the cases having too much movement in the secondary direction. Bug: 5554762 Change-Id: I05fb24bb1ff5446bea0cc1a1de8a02c37fb642d7 --- jni/feature_mos/src/mosaic/Blend.cpp | 37 +++++++++++++++++++++++++++++++++--- jni/feature_mos/src/mosaic/Blend.h | 5 +++++ 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'jni') diff --git a/jni/feature_mos/src/mosaic/Blend.cpp b/jni/feature_mos/src/mosaic/Blend.cpp index 18972ee..cce89ff 100644 --- a/jni/feature_mos/src/mosaic/Blend.cpp +++ b/jni/feature_mos/src/mosaic/Blend.cpp @@ -226,14 +226,25 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes, yTopMost = max(0, max(yTopCorners[0], yTopCorners[1]) - fullRect.top + 1); yBottomMost = min(Mheight - 1, min(yBottomCorners[0], yBottomCorners[1]) - fullRect.top - 1); + if (xRightMost <= xLeftMost || yBottomMost <= yTopMost) + { + LOGE("RunBlend: aborting -consistency check failed," + "(xLeftMost, xRightMost, yTopMost, yBottomMost): (%d, %d, %d, %d)", + xLeftMost, xRightMost, yTopMost, yBottomMost); + return BLEND_RET_ERROR; + } + // Make sure image width is multiple of 4 Mwidth = (unsigned short) ((Mwidth + 3) & ~3); Mheight = (unsigned short) ((Mheight + 3) & ~3); // Round up. - if (Mwidth < width || Mheight < height || xRightMost <= xLeftMost) + ret = MosaicSizeCheck(LIMIT_SIZE_MULTIPLIER, LIMIT_HEIGHT_MULTIPLIER); + if (ret != BLEND_RET_OK) { - LOGE("RunBlend: aborting - consistency check failed, w=%d, h=%d, xLeftMost=%d, xRightMost=%d", Mwidth, Mheight, xLeftMost, xRightMost); - return BLEND_RET_ERROR; + LOGE("RunBlend: aborting - mosaic size check failed, " + "(frame_width, frame_height) vs (mosaic_width, mosaic_height): " + "(%d, %d) vs (%d, %d)", width, height, Mwidth, Mheight); + return ret; } LOGI("Allocate mosaic image for blending - size: %d x %d", Mwidth, Mheight); @@ -296,6 +307,26 @@ int Blend::runBlend(MosaicFrame **oframes, MosaicFrame **rframes, return ret; } +int Blend::MosaicSizeCheck(float sizeMultiplier, float heightMultiplier) { + if (Mwidth < width || Mheight < height) { + return BLEND_RET_ERROR; + } + + if ((Mwidth * Mheight) > (width * height * sizeMultiplier)) { + return BLEND_RET_ERROR; + } + + // We won't do blending for the cases where users swing the device too much + // in the secondary direction. We use a short side to determine the + // secondary direction because users may hold the device in landsape + // or portrait. + int shortSide = min(Mwidth, Mheight); + if (shortSide > height * heightMultiplier) { + return BLEND_RET_ERROR; + } + + return BLEND_RET_OK; +} int Blend::FillFramePyramid(MosaicFrame *mb) { diff --git a/jni/feature_mos/src/mosaic/Blend.h b/jni/feature_mos/src/mosaic/Blend.h index 80bb577..ebb3bdc 100644 --- a/jni/feature_mos/src/mosaic/Blend.h +++ b/jni/feature_mos/src/mosaic/Blend.h @@ -113,6 +113,11 @@ protected: int PerformFinalBlending(YUVinfo &imgMos, MosaicRect &cropping_rect); void CropFinalMosaic(YUVinfo &imgMos, MosaicRect &cropping_rect); + +private: + static const float LIMIT_SIZE_MULTIPLIER = 5.0f * 2.0f; + static const float LIMIT_HEIGHT_MULTIPLIER = 2.5f; + int MosaicSizeCheck(float sizeMultiplier, float heightMultiplier); }; #endif -- cgit v1.1