Fix #109024: Off-by-1 in rna_access for non-array props without raw access #115967

Open
Thomas Barlow wants to merge 4 commits from Mysteryem/blender:fix_109024_non_raw_non_array_off_by_one into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

The a + itemlen > in.len check was off-by-1 whenever accessing a
non-array property without raw access. This was because itemlen was
actually the array length of the property, which is 0 for non-array
properties.

Given an array which was too short, this would cause the slower loop to
overrun the end of the array by one item. When getting items this would
cause a crash on a debug build with Fatal Python error: _PyMem_DebugRawFree: bad trailing pad byte.

The semantics of the itemlen and arraylen variables have now been
swapped to be less confusing. So arraylen is now the array length of
the property and itemlen is now the item length of the property. The
arraylen variable has been given the same scope as itemlen so that
it can be used in the slower loop when raw access is not available.


The band-aid fix would have been to replace a + itemlen > in.len with a + (itemlen == 0 ? 1 : itemlen) > in.len, but I think this patch is a better idea.

The `a + itemlen > in.len` check was off-by-1 whenever accessing a non-array property without raw access. This was because `itemlen` was actually the array length of the property, which is `0` for non-array properties. Given an array which was too short, this would cause the slower loop to overrun the end of the array by one item. When getting items this would cause a crash on a debug build with `Fatal Python error: _PyMem_DebugRawFree: bad trailing pad byte`. The semantics of the `itemlen` and `arraylen` variables have now been swapped to be less confusing. So `arraylen` is now the array length of the property and `itemlen` is now the item length of the property. The `arraylen` variable has been given the same scope as `itemlen` so that it can be used in the slower loop when raw access is not available. --- The band-aid fix would have been to replace `a + itemlen > in.len` with `a + (itemlen == 0 ? 1 : itemlen) > in.len`, but I think this patch is a better idea.
Thomas Barlow added 1 commit 2023-12-09 01:50:00 +01:00
ed25adc3db Fix #109024: Off-by-1 in rna_access for non-array props without raw access
The `a + itemlen > in.len` check was off-by-1 whenever accessing a
non-array property without raw access. This was because `itemlen` was
actually the array length of the property, which is `0` for non-array
properties.

Given an array which was too short, this would cause the slower loop to
overrun the end of the array by one item, causing a crash on a debug
build with `Fatal Python error: _PyMem_DebugRawFree: bad trailing pad
byte`.

The semantics of the `itemlen` and `arraylen` variables have now been
swapped to be less confusing. So `arraylen` is now the array length of
the property and `itemlen` is now the item length of the property. The
`arraylen` variable has been given the same scope as `itemlen` so that
it can be used in the slower loop when raw access is not available.
Iliya Katushenock added this to the Python API project 2023-12-09 11:07:06 +01:00
Thomas Barlow added 1 commit 2023-12-10 04:44:53 +01:00
Thomas Barlow added 2 commits 2023-12-13 05:08:08 +01:00
55430e9666 Update the recently added enum array asserts to use `arraylen`
This patch swaps the semantics of `arraylen` and `itemlen` and the recently added asserts were using the old `itemlen`.
Merge conflict checking is in progress. Try again in few moments.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u fix_109024_non_raw_non_array_off_by_one:Mysteryem-fix_109024_non_raw_non_array_off_by_one
git checkout Mysteryem-fix_109024_non_raw_non_array_off_by_one
Sign in to join this conversation.
No reviewers
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
1 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#115967
No description provided.