Fix: foreach_get/set does not work on multidimensional arrays #116457

Merged
Brecht Van Lommel merged 7 commits from Mysteryem/blender:fix_multidim_prop_array_foreach_getset into main 2024-01-12 18:38:39 +01:00
Member

The foreach_get/foreach_set methods of bpy_prop_array get/set the entire
contents of the array, but they were checking that the length of the
input sequence was equal to the length of the current array dimension
rather than the total length of all dimensions of the array.

This would read/write memory after the end of the passed in sequence
when the property was a multidimensional array. Performing
foreach_get with a Python list with length matching the length of the
current dimension of a multidimensional array would crash a debug build
due to the trailing pad bytes of the temporarily allocated array being
overwritten.

This patch fixes pyprop_array_foreach_getset by changing the function
used to get the expected sequence size, to the RNA function that gets
the total length of the array across all its dimensions.

The tests have be updated to additionally test multidimensional array
properties.


To crash on a debug build, select an Object as active and then run in the Python Console:

C.object.matrix_world.owner.foreach_get([1] * 4)
The foreach_get/foreach_set methods of bpy_prop_array get/set the entire contents of the array, but they were checking that the length of the input sequence was equal to the length of the current array dimension rather than the total length of all dimensions of the array. This would read/write memory after the end of the passed in sequence when the property was a multidimensional array. Performing `foreach_get` with a Python list with length matching the length of the current dimension of a multidimensional array would crash a debug build due to the trailing pad bytes of the temporarily allocated array being overwritten. This patch fixes `pyprop_array_foreach_getset` by changing the function used to get the expected sequence size, to the RNA function that gets the total length of the array across all its dimensions. The tests have be updated to additionally test multidimensional array properties. --- To crash on a debug build, select an Object as active and then run in the Python Console: ```py C.object.matrix_world.owner.foreach_get([1] * 4) ```
Thomas Barlow added 4 commits 2023-12-22 02:11:19 +01:00
beea6dab6a Fix: foreach_get/set does not work on multidimensional arrays
The foreach_get/foreach_set methods of bpy_prop_array get/set the entire
contents of the array, but they were checking that the length of the
input sequence was equal to the length of the current array dimension
rather than the total length of all dimensions of the array.

This would read/write memory after the end of the passed in sequence
when the property was a multidimensional array. Performing
`foreach_get` with a Python list with length matching the length of the
current dimension of a multidimensional array would crash a debug build
due to the trailing pad bytes of the temporarily allocated array being
overwritten.

This patch fixes pyprop_array_foreach_getset by changing the function
used to get the expected sequence size, to the RNA function that gets
the total length of the array across all its dimensions.
Thomas Barlow added 1 commit 2023-12-22 03:35:21 +01:00
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
bdb0b2efd5
Test all dimensions of multidimensional arrays
Thomas Barlow changed title from WIP: Fix: foreach_get/set does not work on multidimensional arrays to Fix: foreach_get/set does not work on multidimensional arrays 2023-12-22 03:56:17 +01:00
Author
Member

Hi @ideasman42, can you check this one-line fix for the Python API? I also updated the tests, but can separate them into a different PR if preferred.

Hi @ideasman42, can you check this one-line fix for the Python API? I also updated the tests, but can separate them into a different PR if preferred.
Iliya Katushenock added this to the Python API project 2024-01-11 10:34:48 +01:00

@blender-bot build

@blender-bot build
Brecht Van Lommel requested review from Campbell Barton 2024-01-12 15:48:30 +01:00
Thomas Barlow added 1 commit 2024-01-12 17:23:00 +01:00
Thomas Barlow added 1 commit 2024-01-12 17:25:19 +01:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
084f6820c1
Merge branch 'main' into fix_multidim_prop_array_foreach_getset
Brecht Van Lommel approved these changes 2024-01-12 17:57:09 +01:00

@blender-bot build

@blender-bot build
Brecht Van Lommel merged commit 5139a9c064 into main 2024-01-12 18:38:39 +01:00
Brecht Van Lommel deleted branch fix_multidim_prop_array_foreach_getset 2024-01-12 18:38:41 +01:00
Sign in to join this conversation.
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
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#116457
No description provided.