Fix unreported: Allow Win32 clipboard to properly handle large images #115018

Merged
Jesse Yurkovich merged 2 commits from deadpin/blender:fixclip into main 2023-11-18 22:46:50 +01:00

The current code ran afoul of various arithmetic overflow conditions
when attempting to either Copy out or Paste in large images that would
overflow either the naive w * h * 4 expression or the size of what the
DibV5 header allowed (DWORD, uint32_t).


To test, you can attempt to paste a 24000x24000 image from one Blender instance into a second Blender's image editor (second Blender will crash).
Or try copying a 32768x32768 image to some other application (the receiving application will most likely fail to paste; Blender inserts a DibV5 header of size 0).

The main issue with w * h * 4 expressions is that they resolve to int at the end of the day. Casting the leftmost variable to a larger, unsigned, type will fix the silent overflows. https://godbolt.org/z/8GPqff55E

The current code ran afoul of various arithmetic overflow conditions when attempting to either Copy out or Paste in large images that would overflow either the naive `w * h * 4` expression or the size of what the DibV5 header allowed (DWORD, uint32_t). ---- To test, you can attempt to paste a 24000x24000 image from one Blender instance into a second Blender's image editor (second Blender will crash). Or try copying a 32768x32768 image to some other application (the receiving application will most likely fail to paste; Blender inserts a DibV5 header of size 0). The main issue with `w * h * 4` expressions is that they resolve to `int` at the end of the day. Casting the leftmost variable to a larger, unsigned, type will fix the silent overflows. https://godbolt.org/z/8GPqff55E
Jesse Yurkovich added 1 commit 2023-11-16 23:10:26 +01:00
Jesse Yurkovich requested review from Harley Acheson 2023-11-16 23:12:13 +01:00
Jesse Yurkovich requested review from Ray molenkamp 2023-11-16 23:12:19 +01:00
Harley Acheson approved these changes 2023-11-17 19:32:28 +01:00
Harley Acheson left a comment
Member

Awesome. Thanks!

Awesome. Thanks!
Ray molenkamp approved these changes 2023-11-17 19:40:48 +01:00
Ray molenkamp left a comment
Member

Accepted provisionally given you make those 2 small changes before landing, doesn't need another review round.

Accepted provisionally given you make those 2 small changes before landing, doesn't need another review round.
@ -2374,0 +2376,4 @@
/* Clipboard data is untrusted. Protect against arithmetic overflow as DibV5
* only supports up to DWORD size bytes. */
if (uint64_t(width) * uint64_t(height) > (std::numeric_limits<DWORD>::max() / 4)) {
Member

nit pick: if (uint64_t(width) * uint64_t(height) * 4 > (std::numeric_limits<DWORD>::max())) {

nit pick: `if (uint64_t(width) * uint64_t(height) * 4 > (std::numeric_limits<DWORD>::max())) {`
Author
Member

With large enough incoming ints, that expression could overflow 64bits if you keep the multiplication on the left side.

With large enough incoming ints, that expression could overflow 64bits if you keep the multiplication on the left side.
Member

fair point, ignore this one, i stand by the #ifdef one though :)

fair point, ignore this one, i stand by the #ifdef one though :)
LazyDodo marked this conversation as resolved
@ -13,6 +13,7 @@
# error WIN32 only!
#endif /* WIN32 */
#define NOMINMAX
Member

please guard this with an #ifndef NOMINMAX to prevent potential warnings

please guard this with an `#ifndef NOMINMAX` to prevent potential warnings
deadpin marked this conversation as resolved
Jesse Yurkovich added 1 commit 2023-11-17 20:01:13 +01:00
buildbot/vexp-code-patch-coordinator Build done. Details
4d9c303fc3
Feedback
Author
Member

@blender-bot build windows

@blender-bot build windows
Jesse Yurkovich merged commit 9eba3902c9 into main 2023-11-18 22:46:50 +01:00
Jesse Yurkovich deleted branch fixclip 2023-11-18 22:46:52 +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
3 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#115018
No description provided.