Select Similar Face Regions triggers AddressSanitizer crash #89247

Closed
opened 2021-06-17 20:16:54 +02:00 by Fen · 8 comments

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 446.14

Blender Version
Broken: version: 3.0.0 Alpha, branch: master. Commit hash: ed4222258e
Worked: Haven't built older versions with ASan yet

Short description of error
Selecting similar faces, by face region, causes AddressSanitizer to crash Blender. It detects a buffer overflow.

Exact steps for others to reproduce the error

  1. In a build of Blender that includes AddressSanitizer, go into edit mode on the default cube
  2. Select at least two faces
  3. Hit F3 and type "select face regions"
  4. Run the operator
  5. Crash

This does not cause a crash without AddressSanitizer being present.

Here's the ASan output:

ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffeefbfa998 at pc 0x000103eb58cd bp 0x7ffeefbfa030 sp 0x7ffeefbfa028
READ of size 4 at 0x7ffeefbfa998 thread T0
    - 0 bm_face_len_cmp source/blender/bmesh/tools/bmesh_region_match.c:558:11
    - 1 wrap_qsort (/Users/ankitkumar/apps/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x3e0e9)
    - 2 bm_uuidwalk_init_from_edge source/blender/bmesh/tools/bmesh_region_match.c:583:3
    - 3 bm_mesh_region_match_pair source/blender/bmesh/tools/bmesh_region_match.c:747:7
    - 4 BM_mesh_region_match source/blender/bmesh/tools/bmesh_region_match.c:1433:20
    - 5 edbm_select_similar_region_exec source/blender/editors/mesh/editmesh_select.c:1316:11
    - 6 wm_operator_invoke source/blender/windowmanager/intern/wm_event_system.c:1362:16
    - 7 wm_operator_call_internal source/blender/windowmanager/intern/wm_event_system.c:1557:18
    - 8 WM_operator_name_call_ptr source/blender/windowmanager/intern/wm_event_system.c:1605:10
    - 9 menu_search_exec_fn source/blender/editors/interface/interface_template_search_menu.c:958:7
    - 10 ui_apply_but_funcs_after source/blender/editors/interface/interface_handlers.c:973:7
    - 11 ui_popup_handler source/blender/editors/interface/interface_handlers.c:11121:3
    - 12 wm_handler_ui_call source/blender/windowmanager/intern/wm_event_system.c:693:16
    - 13 wm_handlers_do_intern source/blender/windowmanager/intern/wm_event_system.c:2842:21
    - 14 wm_handlers_do source/blender/windowmanager/intern/wm_event_system.c:2958:16
    - 15 wm_event_do_handlers source/blender/windowmanager/intern/wm_event_system.c:3378:17
    - 16 WM_main source/blender/windowmanager/intern/wm.c:647:5
    - 17 main source/creator/creator.c:519:5
    #18 start (/usr/lib/system/libdyld.dylib:x86_64+0x163d4)

**System Information** Operating system: Windows-10-10.0.19041-SP0 64 Bits Graphics card: GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 446.14 **Blender Version** Broken: version: 3.0.0 Alpha, branch: master. Commit hash: ed4222258ea6fff51c17a2e244b497f03a8e0162 Worked: Haven't built older versions with ASan yet **Short description of error** Selecting similar faces, by face region, causes AddressSanitizer to crash Blender. It detects a buffer overflow. **Exact steps for others to reproduce the error** 1. In a build of Blender that includes AddressSanitizer, go into edit mode on the default cube 2. Select at least two faces 3. Hit F3 and type "select face regions" 4. Run the operator 5. Crash This does not cause a crash without AddressSanitizer being present. Here's the ASan output: ``` ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffeefbfa998 at pc 0x000103eb58cd bp 0x7ffeefbfa030 sp 0x7ffeefbfa028 READ of size 4 at 0x7ffeefbfa998 thread T0 - 0 bm_face_len_cmp source/blender/bmesh/tools/bmesh_region_match.c:558:11 - 1 wrap_qsort (/Users/ankitkumar/apps/usr/lib/clang/13.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x3e0e9) - 2 bm_uuidwalk_init_from_edge source/blender/bmesh/tools/bmesh_region_match.c:583:3 - 3 bm_mesh_region_match_pair source/blender/bmesh/tools/bmesh_region_match.c:747:7 - 4 BM_mesh_region_match source/blender/bmesh/tools/bmesh_region_match.c:1433:20 - 5 edbm_select_similar_region_exec source/blender/editors/mesh/editmesh_select.c:1316:11 - 6 wm_operator_invoke source/blender/windowmanager/intern/wm_event_system.c:1362:16 - 7 wm_operator_call_internal source/blender/windowmanager/intern/wm_event_system.c:1557:18 - 8 WM_operator_name_call_ptr source/blender/windowmanager/intern/wm_event_system.c:1605:10 - 9 menu_search_exec_fn source/blender/editors/interface/interface_template_search_menu.c:958:7 - 10 ui_apply_but_funcs_after source/blender/editors/interface/interface_handlers.c:973:7 - 11 ui_popup_handler source/blender/editors/interface/interface_handlers.c:11121:3 - 12 wm_handler_ui_call source/blender/windowmanager/intern/wm_event_system.c:693:16 - 13 wm_handlers_do_intern source/blender/windowmanager/intern/wm_event_system.c:2842:21 - 14 wm_handlers_do source/blender/windowmanager/intern/wm_event_system.c:2958:16 - 15 wm_event_do_handlers source/blender/windowmanager/intern/wm_event_system.c:3378:17 - 16 WM_main source/blender/windowmanager/intern/wm.c:647:5 - 17 main source/creator/creator.c:519:5 #18 start (/usr/lib/system/libdyld.dylib:x86_64+0x163d4) ```
Author

Added subscriber: @chemicalcrux

Added subscriber: @chemicalcrux
Member

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

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

Added subscriber: @ankitm

Added subscriber: @ankitm
Author

Here's the issue:

static int bm_face_len_cmp(const void *v1, const void *v2)
{
  const BMFace *f1 = v1, *f2 = v2;

qsort is passing a BMFace** to the cmp function, which then tries to interpret it as a BMFace*. This runs off the end of the pointer and sets off ASan.

Casting to BMFace** and then dereferencing makes things work. Interestingly, the operator was still working properly even with a bogus sort function -- maybe it was just running slower, or something?

Should be an easy fix. I will take a stab at making a patch for this.

Here's the issue: ``` static int bm_face_len_cmp(const void *v1, const void *v2) { const BMFace *f1 = v1, *f2 = v2; ``` `qsort` is passing a `BMFace**` to the cmp function, which then tries to interpret it as a `BMFace*`. This runs off the end of the pointer and sets off ASan. Casting to `BMFace**` and then dereferencing makes things work. Interestingly, the operator was still working properly even with a bogus sort function -- maybe it was just running slower, or something? Should be an easy fix. I will take a stab at making a patch for this.
Fen self-assigned this 2021-06-17 21:23:24 +02:00

This issue was referenced by 129798cacb

This issue was referenced by 129798cacbd9e1cd7f94a8f0c3f8b669d89ca0dc

This issue was referenced by 8dd18a77e7

This issue was referenced by 8dd18a77e72444c5a9cc60c1043fa96b28260d9a

This issue was referenced by e178a273fa

This issue was referenced by e178a273fa7f5c67a617d682b1387cb42a6987cb

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
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
4 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#89247
No description provided.