Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
* [Android] Avoid ArrayIndexOutOfBounds in RenderPage::MoveRenderObje…
Browse files Browse the repository at this point in the history
…ct (#2919)

* * [Android] Avoid ArrayIndexOutOfBounds in RenderPage::MoveRenderObject

* Update import
  • Loading branch information
YorkShen authored and lucky-chen committed Sep 23, 2019
1 parent e8f323a commit ec1ec23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Expand Up @@ -152,6 +152,7 @@ public class WXBridgeManager implements Callback, BactchExecutor {
public static final String METHOD_UPDATE_COMPONENT_WITH_DATA = "UpdateComponentData";
private static final String METHOD_POST_TASK_TO_MSG_LOOP = "PostTaskToMsgLoop";
private static final String METHOD_JSFM_NOT_INIT_IN_EAGLE_MODE = "JsfmNotInitInEagleMode";
private static final String METHOD_MOVE_RENDER_OBJECT = "RenderPage::MoveRenderObject";
public static final String METHOD_DESTROY_INSTANCE = "destroyInstance";
public static final String METHOD_CALL_JS = "callJS";
public static final String METHOD_SET_TIMEOUT = "setTimeoutCallback";
Expand Down Expand Up @@ -2585,6 +2586,8 @@ public void reportJSException(String instanceId, String function,
METHOD_JSFM_NOT_INIT_IN_EAGLE_MODE.equals(function) )
&& !instance.getApmForInstance().hasAddView){
reportErrorCode = WXErrorCode.WX_DEGRAD_EAGLE_RENDER_ERROR;
} else if (METHOD_MOVE_RENDER_OBJECT.equals(function)) {
reportErrorCode = WXErrorCode.WX_ERROR_MOVE_RENDER_OBJECT_OUT_OF_BOUNDS;
}
instance.onJSException(reportErrorCode.getErrorCode(), function, exception);
}
Expand Down
Expand Up @@ -276,6 +276,9 @@ public enum WXErrorCode {

WX_ERR_HASH_MAP_TMP("-10010", "WX_ERR_HASH_MAP_TMP",ErrorType.NATIVE_ERROR,ErrorGroup.NATIVE),

WX_ERROR_MOVE_RENDER_OBJECT_OUT_OF_BOUNDS("-2120", "Index out of bounds when move element",
ErrorType.NATIVE_ERROR, ErrorGroup.JS),

/**
* TEST
*/
Expand Down
10 changes: 10 additions & 0 deletions weex_core/Source/core/render/page/render_page.cpp
Expand Up @@ -221,6 +221,16 @@ bool RenderPage::MoveRenderObject(const std::string &ref,
}
}

if(index > new_parent->getChildCount()){
std::stringstream msg;
msg << "Out of array bounds when RenderPage::MoveRenderObject, specified index: "
<< index << "array size " << new_parent->getChildCount();

WeexCore::WeexCoreManager::Instance()->getPlatformBridge()->platform_side()
->ReportException(page_id().c_str(), "RenderPage::MoveRenderObject", msg.str().c_str());
return false;
}

set_is_dirty(true);
child->getParent()->removeChild(child);
new_parent->addChildAt(child, index);
Expand Down

0 comments on commit ec1ec23

Please sign in to comment.