BLI: Prevent Overflow in Grouped Number Output #105263
No reviewers
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105263
Loading…
Reference in New Issue
No description provided.
Delete Branch "Harley/blender:GroupedOverflow"
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?
Increase the buffer sizes used for
BLI_str_format_uint64_grouped
toprevent overflow on strings representing numbers within the uint64.
Also creates and uses defines for all the formatted string buffer
sizes.
When displaying large numbers we often use
BLI_str_format_uint64_grouped
to add commas as thousands separators. In all the places that we call this, and internal to that function, we use 16-byte characters arrays. This means that it can successfully turn "999999999999" into "999,999,999,999", but will overflow on one trillion or greater as that would require an 18-byte buffer.This patch increases the buffer size used by this function to 27. And also uses a define for this size, and also for those used by
BLI_str_format_byte_unit
,BLI_str_format_decimal_unit
, andBLI_str_format_integer_unit
.Showing
?
seems like a bug from a user perspective, if this were unavoidable it could be an acceptable fallback however increasing the default buffer size to fit the largestuint64_t
is preferable.A quick check shows
len("{:3,d}".format(0xffff_ffff_ffff_ffff))
is 26, so the size ofchar dst[16]
forBLI_str_format_uint64_grouped
should be increased to 27.To avoids hard coded values being duplicated, defines can be added to
BLI_string.h
.eb701771dd
to583bdd73e3
Yes, that works pretty well. About the only "complication" is that we quite often use a combination of these formatted strings so it is hard to do just grouped and not do the byte, unit, and integer formats as well. So this version does that too. Doesn't seem to make too much of a mess. I think its better...
583bdd73e3
to39482f0bd9
Looks good, it also makes sense to have tests these functions are working as expected (passing in min/max for each type, ensuring values aren't clipped).
@ -20,0 +31,4 @@
#define BLI_STR_FORMAT_UINT64_DECIMAL_UNIT_SIZE 7
/* Buffer size of maximum `int32` formatted as very short decimal size ("15B" for example). */
#define BLI_STR_FORMAT_UINT64_INTEGER_UNIT_SIZE 5
Should be BLI_STR_FORMAT_INT32_INTEGER_UNIT_SIZE
BLI: Prevent Overflow in Grouped Number Outputto WIP BLI: Prevent Overflow in Grouped Number OutputHarley: Fix those constants
and update the tests (BLI_string_text.cc). Not sure if all the functions are tested. make sure they all test min/max and use the constants for buffer sizes
39482f0bd9
toe410112e30
WIP BLI: Prevent Overflow in Grouped Number Outputto BLI: Prevent Overflow in Grouped Number Output@ideasman42 - I fixed those constants for size/sign. And added tests for
BLI_str_format_uint64_grouped
and made the rest of them use the new constants.@blender-bot build