Skip to content
Memory corruption Advisory Advanced CVE-2026-5870

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.cpp
  • third_party/skia/src/core/SkWritePixelsRec.cpp
  • third_party/skia/src/core/SkImageInfoPriv.h
  • third_party/skia/include/core/SkImageInfo.h
  • third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.cc
  • third_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:

  1. Guard Bypass in minRowBytes(): In SkReadPixelsRec::trim(), the first safety check is if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()). If the attacker requests an extremely wide ImageData (e.g., width = 268,435,456), SkImageInfo::minRowBytes() calculates width * bytesPerPixel (268,435,456 * 16 = 4,294,967,296). Because this exceeds INT32_MAX, an internal SkTFitsIn<int32_t> check fails, and minRowBytes() returns 0 as an error sentinel. Since fRowBytes is a size_t, fRowBytes < 0 evaluates to false, completely bypassing the safety guard.

  2. 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. If x is a carefully chosen large negative value (e.g., -268,435,455), -x is positive 268,435,455. Multiplied by 16 (the BPP of rgba-float32), the mathematical result is 4,294,967,280. In 32-bit two's complement arithmetic, this overflows and wraps to -16. Adding -16 to fPixels moves 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:

  1. 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.
  2. Prepare Payload: Fill the canvas with a controlled payload using ctx.fillStyle = 'rgba(...)'; ctx.fillRect(0, 0, 1, 1);.
  3. Trigger OOB Write: Call getImageData with carefully chosen parameters:
    JavaScript
    // sx = -268435455, sy = 0, sw = 268435456, sh = 1
    ctx.getImageData(-268435455, 0, 268435456, 1, { pixelFormat: 'rgba-float32' });
    
    • sw is chosen so that sx + sw = 1, satisfying the canvas intersection check in Blink.
    • sx is chosen such that -sx * 16 wraps around to exactly -16 in 32-bit math.
  4. Result: getImageData allocates a ~4GB backing store for the Float32Array. Skia calculates the -16 offset 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

  1. Fix the pointer arithmetic: Cast the operands to ptrdiff_t or size_t before multiplication in both SkReadPixelsRec::trim() and SkWritePixelsRec::trim() to prevent 32-bit integer overflow:
    C++
    fPixels = ((char*)fPixels + (ptrdiff_t)-y * fRowBytes + (ptrdiff_t)-x * fInfo.bytesPerPixel());
    
  2. Fix the sentinel bypass: SkImageInfo::minRowBytes() returning 0 on overflow is dangerous if callers assume it returns a valid minimum size. Update the guards in trim() to explicitly check for the 0 sentinel or bounds-check x and y earlier 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.

The original report as published on the Chromium issue tracker. Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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

  1. Create a 1x1 HTML canvas element.
  2. Fill the canvas with a controlled payload using fillStyle and fillRect.
  3. 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.

More from Google Chrome

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.