Missing checks for #PyObject_GetBuffer success in bpy_prop_collection foreach_get/set and setting idprop arrays #107017
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#107017
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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: 3.5.0, 3.6.0 Alpha, branch: main, commit date: 2023-04-14 19:16, hash:
b86fc55d3005
Worked:
Short description of error
idp_from_PySequence
inidprop_py_api.c
andforeach_getset
inbpy_rna.c
usePyObject_GetBuffer
, but do not check that getting the buffer was successful. This can cause the code to interact with incompatible or uninitialized buffers.Both of these cases request C-contiguous buffers as per their
PyBUF_SIMPLE
request flags. Passing in aPyObject *
that represents a non-C-contiguous buffer will cause thePyObject_GetBuffer
call to fail, but because it's failure is ignored, it can cause code to read from/write to the buffer as if it were C-contiguous, potentially accessing memory outside of the buffer.Permalinks to the uses of
PyObject_GetBuffer
that are not checking for success:Exact steps for others to reproduce the error
It can be a little confusing to set up a test case because the state of a
Py_buffer
from a failedPyObject_GetBuffer
call is not well defined.Numpy
ndarray
objects appear to check compatibility with the buffer request before filling in the buffer's fields, whereasmemoryview
objects appear to fill in the buffer's fields and then check compatibility. In both of these cases in the Blender source, there are additional checks against the buffer's fields to determine if the buffer is compatible for Blender to use, so I've usedmemoryview
objects in the scripts below so that the additional checks against the buffer's fields also pass, causing Blender to erroneously use the incompatible buffer instead of falling back to treating thePyObject *
as a sequence.This script creates an idprop array with a non-contiguous buffer of every other element of an array, but the code ends up reading data from the buffer in a C-contiguous manner instead of falling back to accessing the data as a sequence.
This script attempts to read a mesh's vertex co into a non-contiguous
memoryview
. Because thememoryview
as a buffer is incompatible and becausememoryview
objects are read-only when accessed as a sequence (they havePySequenceMethods.sq_item
so passPySequence_Check()
, but have noPySequenceMethods.sq_ass_item
), the buffer is expected to remain unchanged. The code ends up reading the vertex co into the first C-contiguous bytes of the buffer instead.foreach_set
has the same issue asforeach_get
, but I have not prepared a script for it.