Rust codegen: MapRef::from_valdi and Map::from_valdi do not validate that the value is a map, causing len()/is_empty() to panic

未关闭 适合新手
#238 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

从valdi_core/src/valdi_core/rust/collections.rs开始,并将MapRef::from_valdi与issue指出的验证示例ArrayRef::from_valdi进行比较。检查valdi_rust_value_ref_map_len如何报告非Map值,以及MapRef::len如何处理其结果。当将非Map值反序列化为Map或MapRef时返回错误,而不是允许len()或is_empty()触发panic,即为完成。

由索引模型根据 Issue 内容生成。

描述

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

MapRef::from_valdi and Map::from_valdi do not validate that the value is a map, causing len()/is_empty() to panic

File: valdi_core/src/valdi_core/rust/collections.rs

When a non-map Value (such as a number, string, null, or typed object) is passed from JS or C++ into a Rust function expecting Map or MapRef, deserialization succeeds instead of returning an error, and a subsequent len() or is_empty() call panics. MapRef::from_valdi and Map::from_valdi accept any ValueRef without checking its runtime type, unlike ArrayRef::from_valdi.

Because MapRef::len unwraps valdi_rust_value_ref_map_len with .expect("MapRef always contains a Valdi map"), any non-map value that reaches len() or is_empty() panics instead of failing cleanly during ValdiDeserialize::from_valdi.

Validate the value in MapRef::from_valdi by calling valdi_rust_value_ref_map_len (as ArrayRef::from_valdi does with array_len) and delegate Map::from_valdi through MapRef::from_valdi(value)?.to_owned().

主要语言
C++
星标
16.4k
派生
539
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Snapchat/Valdi 的其他 Issue

查看 Snapchat/Valdi 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。