拒绝切分产物路径中的非法节点标识
在写入 cut 图片前限制节点 ID 字符并确认路径仍位于 sidecar 内。
This commit is contained in:
@@ -183,8 +183,7 @@ fn validate_binding_response_shape(
|
||||
.is_some_and(serde_json::Value::is_object);
|
||||
if !valid_component {
|
||||
return Err(
|
||||
"组件绑定 change 的 component 必须是 PureNode 或 WithComponent 对象"
|
||||
.to_string(),
|
||||
"组件绑定 change 的 component 必须是 PureNode 或 WithComponent 对象".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-4
@@ -187,7 +187,18 @@ pub(crate) async fn separate_ui_impl(
|
||||
extracted_area,
|
||||
} = decision
|
||||
{
|
||||
let cut_path = sidecar.join(format!("cut-{}.png", to_node.as_str()));
|
||||
let node_id = to_node.as_str();
|
||||
if !node_id.chars().all(|character| {
|
||||
character.is_ascii_alphanumeric() || matches!(character, '-' | '_')
|
||||
}) {
|
||||
cut_error = Some(format!("节点 {} 的名称包含非法路径字符", node_id));
|
||||
break;
|
||||
}
|
||||
let cut_path = sidecar.join(format!("cut-{node_id}.png"));
|
||||
if !cut_path.starts_with(&sidecar) {
|
||||
cut_error = Some(format!("节点 {} 的路径越界", node_id));
|
||||
break;
|
||||
}
|
||||
match cut::cut_processed_image(
|
||||
processed_path.clone(),
|
||||
*extracted_area,
|
||||
@@ -200,9 +211,8 @@ pub(crate) async fn separate_ui_impl(
|
||||
.insert(to_node.clone(), project_relative_path(root, &cut_path)?);
|
||||
}
|
||||
Err(error) => {
|
||||
app_log!("ui_separation.error stage=cut_image tree_index={} batch_index={} node_id={} error={error}", tree_index, batch_index, to_node.as_str());
|
||||
cut_error =
|
||||
Some(format!("节点 {} 的分离区域无效:{error}", to_node.as_str()));
|
||||
app_log!("ui_separation.error stage=cut_image tree_index={} batch_index={} node_id={} error={error}", tree_index, batch_index, node_id);
|
||||
cut_error = Some(format!("节点 {} 的分离区域无效:{error}", node_id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user