Renaming Custom Python Properties is Incorrect #98973

Closed
opened 2022-06-18 14:14:17 +02:00 by jon denning · 2 comments
Member

Renaming a custom Python property does not work as expected. In particular, if the property is renamed to a shorter name, the property's new name retains the trailing characters of previous name. This issue does not appear if new name has same length or is longer. Likely, the \0 terminator isn't getting written.

To reproduce: open default scene, switch to the Python Console, and type the following.

>>> C.scene['foo'] = {'bar': 42}     # create custom python property with name 'foo'
>>> list(C.scene.keys())             # print out correct names of custom properties

['foo']

>>> C.scene['foo'].name = 'baz'      # rename 'foo' property to 'baz', same length as 'foo'
>>> list(C.scene.keys())             # print out correct names of custom properties

['baz']

>>> C.scene['baz'].name = 'bazey'    # rename 'baz' property to 'bazey', a LONGER name
>>> list(C.scene.keys())             # print out correct names of custom properties

['bazey']

>>> C.scene['bazey'].name = 'foo'    # rename 'bazey' property to 'foo', a SHORTER name
>>> list(C.scene.keys())             # print out INCORRECT names of custom properties

['fooey']

>>> C.scene['foo'].name              # surprisingly, this is an ERROR!

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
KeyError: 'bpy_struct[key]: key "foo" not found'

>>> C.scene['fooey'].name

'fooey'

>>> C.scene['fooey'].name = 'foo\0'  # rename with explicitly inserted '\0'
>>> list(C.scene.keys())             # print out correct names of custom properties

['foo']

Interestingly, data can be hidden in the names... (possible security issue?)

# create a secret message
C.scene['1 A SECRET MESSAGE IS HIDDEN HERE!'] = {'foo': 42}
list(C.scene.keys())
# ['1 A SECRET MESSAGE IS HIDDEN HERE!']

# hide the secret message
C.scene['1 A SECRET MESSAGE IS HIDDEN HERE!'].name = '1\0'
list(C.scene.keys())
- ['1']
- the secret message is hidden from Python (all asserts below pass)
assert '1' in C.scene
assert '1\0' in C.scene
assert '1\0NOT ORIGINAL SECRET MESSAGE' in C.scene

- IMPORTANT: at this point, we can save as .blend, close and reopen blender,
- then open saved .blend file.  this means that the secret message
#            persists across sessions!  can even run asserts above!

# now, reveal the original secret message
C.scene['1'].name = '1 '  # don't even need to know what the secret message was!
list(C.scene.keys())
# ['1 A SECRET MESSAGE IS HIDDEN HERE!']
Renaming a custom Python property does not work as expected. In particular, if the property is renamed to a *shorter* name, the property's new name retains the trailing characters of previous name. This issue does not appear if new name has same length or is longer. Likely, the `\0` terminator isn't getting written. To reproduce: open default scene, switch to the Python Console, and type the following. ``` >>> C.scene['foo'] = {'bar': 42} # create custom python property with name 'foo' >>> list(C.scene.keys()) # print out correct names of custom properties ['foo'] >>> C.scene['foo'].name = 'baz' # rename 'foo' property to 'baz', same length as 'foo' >>> list(C.scene.keys()) # print out correct names of custom properties ['baz'] >>> C.scene['baz'].name = 'bazey' # rename 'baz' property to 'bazey', a LONGER name >>> list(C.scene.keys()) # print out correct names of custom properties ['bazey'] >>> C.scene['bazey'].name = 'foo' # rename 'bazey' property to 'foo', a SHORTER name >>> list(C.scene.keys()) # print out INCORRECT names of custom properties ['fooey'] >>> C.scene['foo'].name # surprisingly, this is an ERROR! Traceback (most recent call last): File "<blender_console>", line 1, in <module> KeyError: 'bpy_struct[key]: key "foo" not found' >>> C.scene['fooey'].name 'fooey' >>> C.scene['fooey'].name = 'foo\0' # rename with explicitly inserted '\0' >>> list(C.scene.keys()) # print out correct names of custom properties ['foo'] ``` Interestingly, data can be hidden in the names... (possible security issue?) ``` # create a secret message C.scene['1 A SECRET MESSAGE IS HIDDEN HERE!'] = {'foo': 42} list(C.scene.keys()) # ['1 A SECRET MESSAGE IS HIDDEN HERE!'] # hide the secret message C.scene['1 A SECRET MESSAGE IS HIDDEN HERE!'].name = '1\0' list(C.scene.keys()) - ['1'] - the secret message is hidden from Python (all asserts below pass) assert '1' in C.scene assert '1\0' in C.scene assert '1\0NOT ORIGINAL SECRET MESSAGE' in C.scene - IMPORTANT: at this point, we can save as .blend, close and reopen blender, - then open saved .blend file. this means that the secret message # persists across sessions! can even run asserts above! # now, reveal the original secret message C.scene['1'].name = '1 ' # don't even need to know what the secret message was! list(C.scene.keys()) # ['1 A SECRET MESSAGE IS HIDDEN HERE!'] ```
Author
Member

Added subscriber: @gfxcoder

Added subscriber: @gfxcoder

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Philipp Oeser removed the
Interest
Python API
label 2023-02-10 09:04:25 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2023-06-13 19:54:04 +02: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#98973
No description provided.