Single-valued properties accessed with foreach_get/set check for 1 less value than is read/written #109024
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#109024
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.41
Blender Version
Broken: version: 2.79, 2.93.9, 3.5.1, 4.0.0 Alpha, branch: main, commit date: 2023-06-03 14:21, hash:
ab6860f3de0f
Worked:
Short description of error
Most properties, where each property is a single value, accept a list/array that is one element too short when accessed with
foreach_get
andforeach_set
, potentially reading/writing uniitialised memory if the list/array is one element short.This is not the case for properties that contain multiple values and would be flattened by foreach_get/set, such as properties that are usually accessed as a Vector, or for 'FLOAT' and 'INT' type attributes.
Single-valued properties I've checked:
Key.key_blocks
, e.g.my_key.key_blocks.foreach_get("value", my_list)
,Object.vertex_groups
e.g.my_object.vertex_groups.foreach_get("index", my_list)
,Mesh.materials
e.g.my_mesh.materials.foreach_get("roughness", my_list)
,Object.material_slots
e.g.my_obj.material_slots.foreach_get("link", my_list)
Mesh.color_attributes
e.g.my_mesh.color_attributes.foreach_get("is_internal", my_list)
bpy.data.objects
e.g.bpy.data.objects.foreach_get("add_rest_position_attribute", my_list)
MeshEdge.crease
e.g.my_mesh.edges.foreach_get("crease", my_list)
my_mesh.attributes['bool_or_int8_attribute'].data.foreach_get("value", my_list)
Mesh.materials
is extra broken because it accept lists/arrays that are shorter yet again by the number ofNone
materials e.g. If a mesh has 5 materials and no materials areNone
, a 4 length list is accepted. If a mesh has 5 materials and 2 materials areNone
, a 2 length list is accepted.In the examples using
Key.key_blocks
, I've used thevalue
property, but these issues also apply to the other properties usable with foreach_get/set (slider_min
,slider_max
,frame
,mute
andinterpolation
(interpolation
is not a good test because it is an enum which is affected by #92621)).Exact steps for others to reproduce the error
A .blend (authored in 4.0.0a) is attached that contains a default cube with 4 shape keys and the two scripts below copied into two Text Editors.
To show that supplying a list that is one value too short doesn't raise an exception:
key_blocks = C.object.data.shape_keys.key_blocks
my_list = [None]*(len(key_blocks) - 1)
key_blocks.foreach_get("value", my_list)
To show that supplying a list that is two values too short does raise an exception as expected:
key_blocks = C.object.data.shape_keys.key_blocks
my_list = [None]*(len(key_blocks) - 2)
key_blocks.foreach_get("value", my_list)
This script can be run from the Text editor and goes over a number of
foreach_get
cases with lists/arrays that are too shortThis script can be run from the Text Editor and goes over a number of
foreach_set
cases with lists/arrays that are too shortKey.key_blocks (shape keys) foreach_get/set checks for 1 less value than is read/writtento Some foreach_get/set checks for 1 less value than is read/writtenSome foreach_get/set checks for 1 less value than is read/writtento Single-valued properties accessed with foreach_get/set check for 1 less value than is read/writtenConfirmed. There appears to be an off-by-1 in
rna_access.cc