Bug 310770

Summary: utf8Buffer() in SharedBuffer.h allocates too much memory for 8-bit strings
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebCore Misc.Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Chris Dumez
Reported 2026-03-25 22:33:27 PDT
Latin1 characters (0x80-0xFF) encode as at most 2 UTF-8 bytes; ASCII (0x00-0x7F) as 1 byte. So length * 2 is sufficient for 8-bit strings. The 3x multiplier is only needed for 16-bit strings (a single BMP codepoint can be 3 UTF-8 bytes). Additionally, Vector<uint8_t> buffer(length * 3) zero-initializes the entire allocation, so the waste is both allocation and initialization.
Attachments
Chris Dumez
Comment 1 2026-03-25 22:35:17 PDT
EWS
Comment 2 2026-03-26 06:22:29 PDT
Committed 309984@main (65bc0fda9edd): <https://commits.webkit.org/309984@main> Reviewed commits have been landed. Closing PR #61376 and removing active labels.
Radar WebKit Bug Importer
Comment 3 2026-03-26 06:23:13 PDT
Note You need to log in before you can comment on or make changes to this bug.