Integer overflow in Skia (CVE-2026-5870)
An integer overflow in Skia's trim functions allows a negative pointer adjustment when using pixel formats with large bytes-per-pixel values, leading to an out-of-bounds write before the allocated pixel buffer. An attacker could trigger this via the Canvas 2D API to achieve a controlled out-of-bounds memory write in the renderer process.
Google Chrome
Originally disclosed on Chrome VRP
- Fix shipped in 16 days
Project Fortify, an experimental security project, has identified the following potential security issue.
Overview: An integer overflow in Skia's trim functions allows a negative pointer adjustment when using pixel formats with large bytes-per-pixel values (like rgba-float32). This can be triggered via the Canvas 2D API to achieve a precise, attacker-controlled out-of-bounds memory write in the renderer process.
Affected files:
third_party/skia/src/core/SkReadPixelsRec.cppthird_party/skia/src/core/SkWritePixelsRec.cppthird_party/skia/src/core/SkImageInfoPriv.hthird_party/skia/include/core/SkImageInfo.hthird_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.ccthird_party/blink/renderer/core/html/canvas/image_data.cc
Estimated timestamp from git blame: 2023-02-15
Summary
An integer overflow vulnerability exists in SkReadPixelsRec::trim() and SkWritePixelsRec::trim() in Skia (third_party/skia/src/core/SkReadPixelsRec.cpp and SkWritePixelsRec.cpp). When processing image data with more than 4 bytes per pixel (BPP), such as rgba-float32 (16 BPP), an attacker can supply large negative coordinates that bypass bounds checks and overflow during pointer arithmetic. This results in an out-of-bounds (OOB) write to memory located before the allocated pixel buffer in the sandboxed renderer process.
Vulnerability Details
The vulnerability relies on two key flaws:
-
Guard Bypass in
minRowBytes(): InSkReadPixelsRec::trim(), the first safety check isif (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()). If the attacker requests an extremely wideImageData(e.g., width =268,435,456),SkImageInfo::minRowBytes()calculateswidth * bytesPerPixel(268,435,456 * 16 = 4,294,967,296). Because this exceedsINT32_MAX, an internalSkTFitsIn<int32_t>check fails, andminRowBytes()returns0as an error sentinel. SincefRowBytesis asize_t,fRowBytes < 0evaluates tofalse, completely bypassing the safety guard. -
Pointer Adjustment Integer Overflow: Further down in
trim(), to handle negative coordinates (meaning the read/write starts outside the canvas bounds), the pointer is advanced to the first intersecting pixel:C++ fPixels = ((char*)fPixels + -y*fRowBytes + -x*fInfo.bytesPerPixel());The expression
-x * fInfo.bytesPerPixel()performs signed 32-bit integer multiplication. Ifxis a carefully chosen large negative value (e.g.,-268,435,455),-xis positive268,435,455. Multiplied by16(the BPP ofrgba-float32), the mathematical result is4,294,967,280. In 32-bit two's complement arithmetic, this overflows and wraps to-16. Adding-16tofPixelsmoves the destination pointer backwards by 16 bytes, placing it out of bounds before the allocated buffer.
Note: This exploit requires allocating an ArrayBuffer larger than 2GB (up to ~4GB for the specific offsets mentioned), which restricts this vulnerability to 64-bit systems where v8::TypedArray::kMaxByteLength allows such massive allocations.
Potential Attack Steps
(Note: These are suggested theoretical steps as our setup cannot execute code to verify the exploit end-to-end.)
An attacker could trigger this vulnerability via JavaScript using the following steps:
- Setup Canvas: Create a 1x1 HTML
<canvas>element to restrict the read/write size to a single pixel (16 bytes), preventing massive memory corruption and ensuring a stable exploit. - Prepare Payload: Fill the canvas with a controlled payload using
ctx.fillStyle = 'rgba(...)'; ctx.fillRect(0, 0, 1, 1);. - Trigger OOB Write: Call
getImageDatawith carefully chosen parameters:JavaScript // sx = -268435455, sy = 0, sw = 268435456, sh = 1 ctx.getImageData(-268435455, 0, 268435456, 1, { pixelFormat: 'rgba-float32' });swis chosen so thatsx + sw = 1, satisfying the canvas intersection check in Blink.sxis chosen such that-sx * 16wraps around to exactly-16in 32-bit math.
- Result:
getImageDataallocates a ~4GB backing store for theFloat32Array. Skia calculates the-16offset and copies the 16-byte attacker-controlled payload from the canvas exactly 16 bytes before the allocated backing store in the V8 heap (which is highly likely a PartitionAlloc DirectMap allocation). By targeting metadata or adjacent objects, this underflow could be leveraged for renderer RCE.
Suggested Fix
- Fix the pointer arithmetic: Cast the operands to
ptrdiff_torsize_tbefore multiplication in bothSkReadPixelsRec::trim()andSkWritePixelsRec::trim()to prevent 32-bit integer overflow:C++ fPixels = ((char*)fPixels + (ptrdiff_t)-y * fRowBytes + (ptrdiff_t)-x * fInfo.bytesPerPixel()); - Fix the sentinel bypass:
SkImageInfo::minRowBytes()returning0on overflow is dangerous if callers assume it returns a valid minimum size. Update the guards intrim()to explicitly check for the0sentinel or bounds-checkxandyearlier against safer maximums.
Evaluated with Chrome root at commit: 9760e6c70cd33a320713361f17c6dcca85648c0f
Results so far have been promising, but there can be wrong deductions. If this proves to be a false positive, please close as WAI; data from false positives will be used to improve accuracy over time. Please feel free to reach out to me if you have concerns or feedback.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a 32-bit signed integer overflow in pointer arithmetic combined with a sentinel value bypass in a bounds check.
Impact
This could allow an attacker to write controlled data out of bounds in the renderer process, potentially leading to renderer remote code execution, though the exploit requires a 64-bit system and a large memory allocation.
What the attacker needed
64-bit system; Ability to allocate >2GB ArrayBuffer; Victim visits a malicious webpage
The fix
The pointer arithmetic should be fixed by casting operands to a larger type before multiplication, and the sentinel bypass should be addressed by explicitly checking for the zero sentinel or bounds-checking coordinates earlier.
How it was found
- Create a 1x1 HTML canvas element.
- Fill the canvas with a controlled payload using fillStyle and fillRect.
- Call getImageData with carefully chosen parameters that cause the overflow.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Skia is a graphics library used by browsers to draw images. When you ask a browser to read pixels from a canvas, it calculates where in memory to write the data. A maths error in that calculation can make the browser write data to the wrong place, potentially letting an attacker corrupt memory.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.