Multiple issues in array data setter
还没有人认领这个 Issue。
评估
调研方向
从链接的 poc_idl_array.py 复现开始,将数组元素赋值与 issue 中描述的内置类型行为进行比较。跟踪为固定数组生成的 Python 消息类,然后为数值、bool、byte 和 string 数组补充范围和类型拒绝的覆盖;当无效赋值都能一致地失败,同时合法值仍能成功时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Bug report
Required Info:
- Operating System:
- Ubuntu 20.04
- Installation type:
- Binary installation via
apt
- Binary installation via
- Version or commit hash:
- foxy
- DDS implementation:
- Fast-RTPS
- Client library (if applicable):
- N/A
Steps to reproduce issue
- Clone and build messages
$ mkdir -p ~/idltest_ws/src
$ cd ~/idltest_ws/src
$ git clone [email protected]:squizz617/idltest_msgs.git
$ cd ~/idltest_ws
$ colcon build --symlink-install
- Source workspaces (replace zsh with bash if using Bash)
$ source /opt/ros/foxy/setup.zsh
$ source ~/idltest_ws/install/setup.zsh
- Download and run PoC
$ wget https://gist.githubusercontent.com/squizz617/13631a18d25a1b7836414cce0c579227/raw/3e5113c78f2b1b7fe3296a2b29298afad6d8349e/poc_idl_array.py
$ chmod a+x poc_idl_array.py
$ ./poc_idl_array.py
Expected behavior
The PoC is self-explanatory. On the fixed arrays of built-in types, it tests the following three properties: (1) setting legitimate values should succeed, (2) setting out-of-valid-range values should fail, and (3) setting values of mismatching types should fail.
Actual behavior
The issues can be broadly categorized into three types.
- Missing range checks for numeric type (integer and float) arrays
uint8 array allows out of range integers to be assigned:
from idltest_msgs.msg import UInt8FixedArray
ui8fa = UInt8FixedArray()
ui8fa.data[0] = -1 # should fail but doesn't
print(ui8fa.data[0]) # value becomes 255
ui8fa.data[1] = 256 # should fail but doesn't
print(ui8fa.data[1]) # value becomes 0
int8 array also allows out of range integers to be assigned:
from idltest_msgs.msg import Int8FixedArray
i8fa = Int8FixedArray()
ui8fa.data[0] = -129 # should fail but doesn't
print(ui8fa.data[0]) # value becomes 127
ui8fa.data[1] = 128 # should fail but doesn't
print(ui8fa.data[1]) # value becomes -128
float32 array allows double to be assigned:
from idltest_msgs.msg import Float32FixedArray
f32fa = Float32FixedArray()
f32fa.data[0] = 1.0e+365 # should fail but doesn't
print(f32fa.data[0]) # value becomes inf
- Auto casting of data of wrong types
Integer arrays accept floats and casts them to int, dropping precision:
i8fa = Int8FixedArray()
i8fa.data[2] = 3.141592 # should fail but doesn't
print(i8fa.data[2]) # value becomes 3
i8fa.data[3] = 314.1592 # should fail but doesn't
print(i8fa.data[3]) # value becomes 58
For the types that cannot be casted to int, the assignment fails but the exception is raised not by the IDL:
i8fa.data[4] = "string" # fails (int() casting failure, not idl type check failure)
i8fa.data[5] = \x00 # fails (int() casting failure, not idl type check failure)
- Missing type checks for bool, byte, and string arrays
Any data of any type can be assigned to bool, byte or string arrays:
boolfa = BoolFixedArray()
bytefa = ByteFixedArray()
sfa = StringFixedArray()
# nothing fails
boolfa.data[0] = 32
boolfa.data[1] = 3.141592
boolfa.data[2] = 1.0e+365
boolfa.data[3] = 3.141592
boolfa.data[4] = "string"
boolfa.data[5] = [1, 2, 3]
boolfa.data[6] = {1: 2}
print(boolfa) # the illegitimate values are assigned as is
bytefa.data[0] = 32
bytefa.data[1] = 3.141592
bytefa.data[2] = 1.0e+365
bytefa.data[3] = 3.141592
bytefa.data[4] = "string"
bytefa.data[5] = [1, 2, 3]
bytefa.data[6] = {1: 2}
print(bytefa) # the illegitimate values are assigned as is
sfa.data[0] = 32
sfa.data[1] = 3.141592
sfa.data[2] = 1.0e+365
sfa.data[3] = 3.141592
sfa.data[4] = [1, 2, 3]
sfa.data[5] = {1: 2}
print(sfa) # the illegitimate values are assigned as is
In a nutshell, array elements are not properly checked at the time of assignment, unlike what's done for the built-in types (e.g., we cannot assign 256 or 3.14 to a uint8 variable, we cannot assign 3.14 to a string variable, ...).
- 主要语言
- EmberScript
- 星标
- 26
- 派生
- 68
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ros2/rosidl_python 的其他 Issue
-
Eliminate array resetting loop in _msg_support.c.em可能已有人在做 @Lidang-Jiang 于 164 天前认领。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 72/100
ros2/rosidl_python#255 · 1 个 reaction ·
-
bug
难度 3/5 1-2 天 新手友好度 56/100
ros2/rosidl_python#264 · 2 条评论 ·
-
Message named pkg/Duration with field builtin_interfaces/Duration is invalid可能已有人在做 @Lidang-Jiang 于 163 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 55/100
ros2/rosidl_python#257 · 8 条评论 ·
-
enhancement
难度 3/5 1-2 天 新手友好度 35/100
ros2/rosidl_python#242 ·
-
难度 3/5 1-2 天 新手友好度 32/100
ros2/rosidl_python#219 · 2 条评论 ·
查看 ros2/rosidl_python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
python-caldav/caldav#735 ·
维护者通常 1 天内回复
-
bug triage
难度 2/5 1-3 小时 新手友好度 68/100
mealie-recipes/mealie#8682 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
PhilflowIO/dav-mcp#146 ·
维护者通常 1 天内回复
-
Component: Python API
难度 2/5 1-3 小时 新手友好度 70/100
Vector35/binaryninja-api#8649 ·
维护者通常 3 天内回复