chore: Add width/height verification to avoid OOM on image resize
MODIFY
lib/basedriver/commands/find.js
lib/basedriver/commands/find.js
@@ -354,6 +354,12 @@ helpers.getScreenshotForImageFind = async function getScreenshotForImageFind (sc
return {b64Screenshot};
}
+ if (screenWidth < 1 || screenHeight < 1) {
+ log.warn(`The retrieved screen size ${screenWidth}x${screenHeight} does ` +
+ `not seem to be valid. No changes will be applied to the screenshot`);
+ return {b64Screenshot};
+ }
+
// otherwise, do some verification on the screenshot to make sure it matches
// the screen size and aspect ratio
log.info('Verifying screenshot size and aspect ratio');
@@ -361,6 +367,12 @@ helpers.getScreenshotForImageFind = async function getScreenshotForImageFind (sc
let imgObj = await imageUtil.getJimpImage(b64Screenshot);
let {width: shotWidth, height: shotHeight} = imgObj.bitmap;
+ if (shotWidth < 1 || shotHeight < 1) {
+ log.warn(`The retrieved screenshot size ${shotWidth}x${shotHeight} does ` +
+ `not seem to be valid. No changes will be applied to the screenshot`);
+ return {b64Screenshot};
+ }
+
if (screenWidth === shotWidth && screenHeight === shotHeight) {
// the height and width of the screenshot and the device screen match, which
// means we should be safe when doing template matches

chore: Add width/height verification to avoid OOM on image resize (#393)