Integer overflow in ANGLE (CVE-2026-7340)
The ANGLE D3D11 backend computes the zero-fill buffer size for block-compressed 3D textures using an unchecked 32-bit multiplication that does not account for block height, producing a value four times larger than the actual compressed image size. For sufficiently large textures the product wraps around in a GLuint, and the subsequent LoadCompressedToNative memcpy reads the correct (larger) number of bytes from the undersized buffer, causing a heap-buffer-overflow read in the GPU process.
86ac1f1587b71893ed2ad792cd7dde32 Follow
Originally disclosed on Chrome VRP
- Fix shipped in 30 days
Summary
The ANGLE D3D11 backend computes the zero-fill buffer size for block-compressed 3D textures using an unchecked 32-bit multiplication that does not account for block height, producing a value four times larger than the actual compressed image size. For sufficiently large textures the product wraps around in a GLuint, and the subsequent LoadCompressedToNative memcpy reads the correct (larger) number of bytes from the undersized buffer. Any WebGL2 page can trigger this through standard API calls (texStorage3D followed by a partial compressedTexSubImage3D), causing a heap-buffer-overflow read in the GPU process with no source modifications required. Platform: Windows (D3D11 ANGLE backend). Any GPU with BPTC (BC6H/BC7) support, which is standard on all Direct3D 11 hardware.
Bisect
Introducing Commit: 05b35b210ef3dcdf7e3260d192ce51b602b6f3a7 (ANGLE repo)
- Date: 2017-10-03
- Author: Jamie Madill ([email protected])
This commit introduced TextureD3D::initializeContents with the slow-path zero-fill logic. The function computes imageBytes as computeRowPitch(...) * height * depth, which for block-compressed formats treats height as a pixel count rather than a block count, inflating the result by blockHeight (4 for BPTC). The computation has been present in every subsequent revision of this function.
Root Cause
When a compressed 3D texture has deferred initialization pending and the fast render-target-clear path is unavailable (which is always the case for block-compressed formats since they have no renderable format), TextureD3D::initializeContents falls through to a slow path that allocates a zero-filled buffer and loads it into the texture through the normal compressed data upload path.
The slow path computes the buffer size as follows:
// third_party/angle/src/libANGLE/renderer/d3d/TextureD3D.cpp
GLuint imageBytes = 0;
ANGLE_CHECK_GL_MATH(contextD3D, formatInfo.computeRowPitch(formatInfo.type, image->getWidth(),
1, 0, &imageBytes));
imageBytes *= image->getHeight() * image->getDepth();
For BPTC (4x4 blocks, 16 bytes per block), computeRowPitch correctly returns (width / 4) * 16. However, the subsequent multiplication uses the raw pixel height rather than the block-row count height / 4. The result is exactly four times larger than the true compressed image size. The multiplication is performed in GLuint (32-bit unsigned) arithmetic with no overflow check.
The validation layer in ValidateCompressedTexImage3D computes the correct compressed size through computeCompressedImageSize, which properly divides by blockHeight. The two computations therefore disagree on image size for any 3D compressed texture.
For a 2048x2048x320 BPTC texture, the correct compressed size is 512 * 512 * 320 * 16 = 1,342,177,280 bytes. The initializeContents formula produces 8192 * 2048 * 320 = 5,368,709,120, which wraps to 1,073,741,824 in GLuint. Context::getZeroFilledBuffer allocates this smaller buffer. Image11::loadData then recomputes the correct inputImageSize and issues a memcpy of that length from the undersized source, reading past the end of the allocation.
The deferred-init state is reached through standard WebGL2 API usage. Calling texStorage3D with a compressed internal format allocates immutable storage and marks all levels as MayNeedInit under robust resource initialization. A subsequent compressedTexSubImage3D on a small sub-region triggers ensureSubImageInitialized, which calls initializeContents for the entire mip level. The BPTC format on D3D11 has texFormat set to a valid DXGI format but rtvFormat set to DXGI_FORMAT_UNKNOWN, ensuring the fast clear path is never taken and the vulnerable slow path is always exercised.
Reproduce
This issue was tested on Chromium commit cd400b8c25335a1e2a8f3676367a21b1c82e1df1 running on Windows 11 with an NVIDIA GeForce RTX 4060 Ti. The bug is in the ANGLE D3D11 backend and requires only the default Windows GPU configuration with BPTC (BC6H/BC7) texture compression support, which is standard on all Direct3D 11 hardware. No source modifications are required to reproduce.
Configure an ASAN build with the following args.gn in out/asan, then build.
is_asan = true
is_debug = false
dcheck_always_on = false
target_cpu = "x64"
autoninja -C out/asan chrome
Launch Chrome and open the PoC page(poc.html uses absolute path).
$ out\asan\chrome.exe --user-data-dir=/tmp/poc /path/to/poc.html 2>/tmp/asan.txt
$ cat /tmp/asan.txt
The PoC page creates a WebGL2 context, obtains the EXT_texture_compression_bptc extension, and calls texStorage3D with GL_TEXTURE_3D, COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, and dimensions 2048x2048x320. This allocates immutable compressed storage with all levels marked for deferred initialization. A subsequent compressedTexSubImage3D on a 4x4x1 sub-region triggers ensureSubImageInitialized, which calls TextureD3D::initializeContents. The overflowing size formula causes allocation of an undersized buffer, and the subsequent memcpy reads past its end. The GPU process crashes with a heap-buffer-overflow reported by AddressSanitizer.
AddressSanitizer reports the following in the GPU process:
=================================================================
==23284==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x12b328cb1800 at pc 0x7ffaa14db36c bp 0x00b7e95fd4a0 sp 0x00b7e95fd4e8
READ of size 1342177280 at 0x12b328cb1800 thread T0
==23284==*** WARNING: Failed to initialize DbgHelp! ***
==23284==*** Most likely this means that the app is already ***
==23284==*** using DbgHelp, possibly with incompatible flags. ***
==23284==*** Due to technical reasons, symbolization might crash ***
==23284==*** or produce wrong results. ***
#0 0x7ffaa14db36b in _asan_memcpy+0x25b (D:\src\chromium\src\out\asan\clang_rt.asan_dynamic-x86_64.dll+0x18004b36b)
#1 0x7ffa968870f3 in angle::LoadCompressedToNative<4,4,1,16> D:\src\chromium\src\third_party\angle\src\image_util\loadimage.inc:389
#2 0x7ffa9696efb4 in rx::Image11::loadData D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\d3d11\Image11.cpp:308
#3 0x7ffa96aa7be1 in rx::TextureD3D::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\TextureD3D.cpp:968
#4 0x7ffa9668789c in gl::FramebufferAttachmentObject::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\FramebufferAttachment.cpp:365
#5 0x7ffa967a52e8 in gl::Texture::setCompressedSubImage D:\src\chromium\src\third_party\angle\src\libANGLE\Texture.cpp:1494
#6 0x7ffa96611e67 in gl::Context::compressedTexSubImage3D D:\src\chromium\src\third_party\angle\src\libANGLE\Context.cpp:5804
......
The full ASAN log is provided in asan.txt.
References
- TextureD3D::initializeContents slow-path size computation
- ValidateCompressedTexImage3D correct size computation
- LoadCompressedToNative memcpy with correct size
- Image11::loadData computing correct inputDepthPitch
Credit
Please use 86ac1f1587b71893ed2ad792cd7dde32 as the credit for this vulnerability. Thank you.
Context
ANGLE is the translation layer Chrome uses to turn WebGL and OpenGL ES calls into the native graphics API of the platform. On Windows that native API is Direct3D 11, and the relevant code lives in the D3D11 backend of ANGLE (rx::TextureD3D, rx::Image11).
The feature involved is robust resource initialisation. When an application allocates immutable texture storage with texStorage3D and then writes only part of it, ANGLE must ensure the untouched regions contain defined values rather than stale GPU memory. For renderable formats it can clear the texture through a fast render-target path. For formats that cannot be rendered to, such as block-compressed formats, it falls back to a slow path: allocate a zero-filled buffer on the CPU and upload it through the normal compressed data path.
The bug is in the size calculation for that zero-filled buffer. For block-compressed 3D textures the calculation uses the pixel height instead of the block-row count, so the computed size is four times too large for BPTC. For a sufficiently large texture the 32-bit product wraps, the buffer allocated is smaller than the real image, and the subsequent memcpy reads past its end in the GPU process.
Setup
The issue was tested on Chromium commit [redacted] on Windows 11 with an NVIDIA GeForce RTX 4060 Ti. It requires only the default Windows GPU configuration with BPTC (BC6H/BC7) texture compression support, which the report describes as standard on all Direct3D 11 hardware. No source modifications are needed to reproduce.
The build is an AddressSanitizer build configured with the following args.gn in out/asan:
is_asan = true
is_debug = false
dcheck_always_on = false
target_cpu = "x64"
and built with:
autoninja -C out/asan chrome
Finding it
The starting point is the slow-path zero-fill in TextureD3D::initializeContents. The function computes the image size as computeRowPitch(...) * height * depth. For block-compressed formats, computeRowPitch correctly accounts for the block width, but the following multiplication treats height as a pixel count rather than a block count. For BPTC, whose blocks are 4x4, that inflates the result by the block height of 4.
The multiplication is performed in GLuint, a 32-bit unsigned type, with no overflow check. The validation layer in ValidateCompressedTexImage3D computes the correct compressed size through computeCompressedImageSize, which does divide by blockHeight. The two computations therefore disagree on the image size for any 3D compressed texture, and the disagreement becomes an overflow once the inflated product exceeds 2^32.
The report traces the mistake back to commit [redacted] in the ANGLE repository, dated 2017-10-03 and authored by Jamie Madill, which introduced TextureD3D::initializeContents with this slow-path logic. The computation has been present in every subsequent revision of the function.
Exploitation
Step 1: allocate immutable compressed 3D storage
The PoC page creates a WebGL2 context, obtains the EXT_texture_compression_bptc extension, and calls texStorage3D with GL_TEXTURE_3D, COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT and dimensions 2048x2048x320. This allocates immutable compressed storage and, under robust resource initialisation, marks all levels as MayNeedInit.
Step 2: write a small sub-region
A subsequent compressedTexSubImage3D on a 4x4x1 sub-region triggers ensureSubImageInitialized, which calls initializeContents for the entire mip level. Because the BPTC format on D3D11 has texFormat set to a valid DXGI format but rtvFormat set to DXGI_FORMAT_UNKNOWN, the fast render-target-clear path is never available, so the vulnerable slow path is always taken.
Step 3: observe the overflow and the out-of-bounds read
For the 2048x2048x320 BPTC texture, the correct compressed size is 512 * 512 * 320 * 16 = 1,342,177,280 bytes. The initializeContents formula produces 8192 * 2048 * 320 = 5,368,709,120, which wraps to 1,073,741,824 in GLuint. Context::getZeroFilledBuffer allocates this smaller buffer. Image11::loadData then recomputes the correct inputImageSize and issues a memcpy of that length from the undersized source, reading past the end of the allocation.
The PoC is launched with:
$ out\asan\chrome.exe --user-data-dir=/tmp/poc /path/to/poc.html 2>/tmp/asan.txt
$ cat /tmp/asan.txt
The GPU process crashes with a heap-buffer-overflow reported by AddressSanitizer:
=================================================================
==23284==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x12b328cb1800 at pc 0x7ffaa14db36c bp 0x00b7e95fd4a0 sp 0x00b7e95fd4e8
READ of size 1342177280 at 0x12b328cb1800 thread T0
==23284==*** WARNING: Failed to initialize DbgHelp! ***
==23284==*** Most likely this means that the app is already ***
==23284==*** using DbgHelp, possibly with incompatible flags. ***
==23284==*** Due to technical reasons, symbolization might crash ***
==23284==*** or produce wrong results. ***
#0 0x7ffaa14db36b in _asan_memcpy+0x25b (D:\src\chromium\src\out\asan\clang_rt.asan_dynamic-x86_64.dll+0x18004b36b)
#1 0x7ffa968870f3 in angle::LoadCompressedToNative<4,4,1,16> D:\src\chromium\src\third_party\angle\src\image_util\loadimage.inc:389
#2 0x7ffa9696efb4 in rx::Image11::loadData D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\d3d11\Image11.cpp:308
#3 0x7ffa96aa7be1 in rx::TextureD3D::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\TextureD3D.cpp:968
#4 0x7ffa9668789c in gl::FramebufferAttachmentObject::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\FramebufferAttachment.cpp:365
#5 0x7ffa967a52e8 in gl::Texture::setCompressedSubImage D:\src\chromium\src\third_party\angle\src\libANGLE\Texture.cpp:1494
#6 0x7ffa96611e67 in gl::Context::compressedTexSubImage3D D:\src\chromium\src\third_party\angle\src\libANGLE\Context.cpp:5804
......
The stack shows the read of 1,342,177,280 bytes in _asan_memcpy, called from angle::LoadCompressedToNative<4,4,1,16> at loadimage.inc:389, from rx::Image11::loadData at Image11.cpp:308, from rx::TextureD3D::initializeContents at TextureD3D.cpp:968, reached through gl::FramebufferAttachmentObject::initializeContents, gl::Texture::setCompressedSubImage and gl::Context::compressedTexSubImage3D. The full ASAN log is provided in asan.txt.
Root cause
The slow path computes the buffer size as follows:
// third_party/angle/src/libANGLE/renderer/d3d/TextureD3D.cpp
GLuint imageBytes = 0;
ANGLE_CHECK_GL_MATH(contextD3D, formatInfo.computeRowPitch(formatInfo.type, image->getWidth(),
1, 0, &imageBytes));
imageBytes *= image->getHeight() * image->getDepth();
For BPTC (4x4 blocks, 16 bytes per block), computeRowPitch correctly returns (width / 4) * 16. The subsequent multiplication, however, uses the raw pixel height rather than the block-row count height / 4, so the result is exactly four times larger than the true compressed image size. The multiplication happens in GLuint arithmetic with no overflow check, so for large textures the product wraps and the allocated buffer is smaller than the data that will be copied into it.
The existing validation does not catch this because it is not the same computation. ValidateCompressedTexImage3D uses computeCompressedImageSize, which properly divides by blockHeight. The two paths therefore disagree on image size for any 3D compressed texture, and nothing reconciles them before the upload.
Impact
The immediate effect is a heap-buffer-overflow read in the GPU process, triggered by any WebGL2 page through standard API calls (texStorage3D followed by a partial compressedTexSubImage3D), with no source modifications required. The weakness is an integer overflow. The conditions are a Windows D3D11 ANGLE backend and a GPU with BPTC (BC6H/BC7) support, which the report describes as standard on all Direct3D 11 hardware.
Fix
The report does not describe a fix. The report does not describe a fix.
Variants to test
- Other block-compressed formats with a block height other than 4, such as ETC or ASTC where supported. A positive result is the same mismatch between the slow-path size and the validated compressed size, with the inflation factor matching the block height.
- 2D compressed textures that reach the same slow path. A positive result is an oversized allocation or an overflow in the same
imageBytescomputation when the height is treated as a pixel count. - Other callers of
computeRowPitchthat multiply the result by a pixel height. A positive result is a second size computation that disagrees withcomputeCompressedImageSizefor compressed formats. - Texture dimensions chosen so the inflated product lands just above 2^32. A positive result is a wrapped
GLuintthat is smaller than the correct compressed size, followed by an out-of-bounds read inLoadCompressedToNative. - The same deferred-initialisation path on other backends, such as the Vulkan or GL backends of ANGLE. A positive result is a zero-fill allocation whose size differs from the validated compressed image size.
What happened, in plain words
Chrome draws 3D graphics on web pages through a system called WebGL. On Windows, Chrome does not talk to the graphics card directly: it passes the drawing instructions through a translator called ANGLE, which turns them into Direct3D 11 commands, the language Windows graphics drivers understand. This report is about a mistake inside that translator.
When a web page asks for a texture (a block of image data stored on the graphics card) but only fills in part of it, Chrome has a rule: the parts nobody wrote to must contain zeros, not leftover data from whatever used that memory before. To honour that rule, ANGLE sometimes builds a buffer full of zeros on the normal processor and copies it into the texture. The bug is in how ANGLE calculates the size of that zero-filled buffer for a particular kind of compressed 3D texture. The calculation comes out four times too large, and for a big enough texture the number wraps around, like a car odometer rolling over, and becomes smaller than it should be. ANGLE then allocates a buffer that is too small and copies more data out of it than it holds, reading past its end. That is a memory safety bug, and it crashes the part of Chrome that talks to the GPU.
The important part for a beginner: no special tools, no malicious website tricks and no modified browser are needed. A normal web page using standard WebGL2 calls is enough. The weakness is an integer overflow.
Context
What ANGLE is
A web page cannot command a graphics card directly, for the same reason a tourist cannot walk into a restaurant kitchen and cook: the kitchen has its own rules and language. Browsers provide an API (Application Programming Interface), a defined set of function calls a page may use, and the browser translates those calls into whatever the operating system and hardware need. WebGL is the web API for 3D graphics. ANGLE is the piece of Chrome that translates WebGL (and its desktop cousin OpenGL ES) into the native graphics API of the machine. On Windows, that native API is Direct3D 11, usually shortened to D3D11. The code involved lives in ANGLE's D3D11 backend, in two components named rx::TextureD3D and rx::Image11.
What robust resource initialisation is
Graphics memory is reused constantly. If a page asks for a texture and writes only part of it, the unwritten part could otherwise contain whatever the previous user of that memory left behind, which might be another page's data. To prevent that, ANGLE uses robust resource initialisation: every part of a newly allocated texture that the page has not written must read back as a defined value, normally zero.
There are two ways to fill those untouched regions with zeros:
- A fast path, where the texture format can be drawn into like a picture. The GPU itself clears it.
- A slow path, used when the format cannot be drawn into. ANGLE builds a zero-filled buffer in ordinary memory on the CPU and uploads it through the normal texture upload code.
Block-compressed formats are formats that store image data in small chunks (blocks) rather than pixel by pixel, to save memory. They cannot be drawn into, so they always take the slow path. The bug lives in the size calculation for that slow path.
The bug in one sentence
For block-compressed 3D textures, the slow path calculates the buffer size using the texture's height in pixels instead of its height in blocks. For the BPTC format, whose blocks are 4 by 4 pixels, that makes the result four times too large. For a sufficiently large texture, the 32-bit number used to hold the size wraps around, the buffer allocated is smaller than the real image, and the copy that follows reads past the end of it in the GPU process.
Setup
What was tested and where
The issue was tested on Chromium commit [redacted] on Windows 11 with an NVIDIA GeForce RTX 4060 Ti graphics card. It needs only the default Windows GPU configuration with BPTC (BC6H/BC7) texture compression support, which the report describes as standard on all Direct3D 11 hardware. No source modifications are needed to reproduce it.
What an AddressSanitizer build is
A normal browser, when it reads past the end of a buffer, often does nothing visible: the read succeeds because the memory after the buffer happens to be mapped. AddressSanitizer (ASAN) is a debugging tool built into the compiler that adds checks around every memory access, so an out-of-bounds read is caught immediately and reported with a stack trace. To see the bug clearly, the researcher built Chrome with ASAN enabled.
The build is configured with the following args.gn file in the out/asan directory:
is_asan = true
is_debug = false
dcheck_always_on = false
target_cpu = "x64"
Line by line:
is_asan = trueturns on AddressSanitizer, the memory checker described above.is_debug = falsebuilds an optimised (release-style) browser rather than a slow debug build, while still keeping the ASAN checks.dcheck_always_on = falsedisables debug assertions, so the build behaves like a normal release build apart from ASAN.target_cpu = "x64"builds for 64-bit x86 processors.
It is then built with:
autoninja -C out/asan chrome
autoninjais Chromium's build tool wrapper; it runs the underlying build system with sensible defaults.-C out/asantells it to build in theout/asandirectory, where the configuration above lives.chromeis the build target: the browser executable.
Finding it
Where the mistake is
The starting point is the slow-path zero-fill in TextureD3D::initializeContents. The function computes the image size as computeRowPitch(...) * height * depth. For block-compressed formats, computeRowPitch correctly accounts for the block width, but the following multiplication treats height as a pixel count rather than a block count. For BPTC, whose blocks are 4x4, that inflates the result by the block height of 4.
Why the number wraps
The multiplication is performed in GLuint, a 32-bit unsigned integer type. A 32-bit unsigned number can hold values from 0 to 4,294,967,295. Add one more and it wraps back to 0, exactly like a mechanical odometer rolling from 999999 to 000000. There is no overflow check, so nothing notices when the product passes that limit. The validation layer in ValidateCompressedTexImage3D computes the correct compressed size through computeCompressedImageSize, which does divide by blockHeight. The two computations therefore disagree on the image size for any 3D compressed texture, and the disagreement becomes an overflow once the inflated product exceeds 2^32 (4,294,967,296).
When the mistake was introduced
The report traces the mistake back to commit [redacted] in the ANGLE repository, dated 2017-10-03 and authored by Jamie Madill, which introduced TextureD3D::initializeContents with this slow-path logic. A commit is a recorded change in a source code repository, with an identifier, a date and an author. The computation has been present in every subsequent revision of the function.
Exploitation
Step 1: allocate immutable compressed 3D storage
The PoC (proof of concept, a small page that demonstrates the bug) creates a WebGL2 context, obtains the EXT_texture_compression_bptc extension, and calls texStorage3D with GL_TEXTURE_3D, COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT and dimensions 2048x2048x320. This allocates immutable compressed storage and, under robust resource initialisation, marks all levels as MayNeedInit.
In plain words:
- A WebGL2 context is the page's handle to the graphics system, the object through which all drawing calls are made.
EXT_texture_compression_bptcis an optional extension that enables the BPTC family of compressed texture formats. A page must ask for it before using those formats.texStorage3Dreserves space for a 3D texture, a stack of 2D slices rather than a single flat image. The dimensions 2048x2048x320 mean 2048 pixels wide, 2048 pixels tall and 320 slices deep.- Immutable means the size and format are fixed at allocation and cannot be changed later.
MayNeedInitis an internal marker meaning "this region has not been written yet and must be zero-filled before anyone reads it".
Step 2: write a small sub-region
A subsequent compressedTexSubImage3D on a 4x4x1 sub-region triggers ensureSubImageInitialized, which calls initializeContents for the entire mip level. Because the BPTC format on D3D11 has texFormat set to a valid DXGI format but rtvFormat set to DXGI_FORMAT_UNKNOWN, the fast render-target-clear path is never available, so the vulnerable slow path is always taken.
In plain words:
compressedTexSubImage3Duploads a small piece of compressed image data into part of the texture. Here the piece is 4 pixels by 4 pixels by 1 slice, tiny compared with the 2048x2048x320 allocation.ensureSubImageInitializedis the internal function that makes sure the rest of the texture is zeroed before the upload proceeds.- A mip level is one resolution of a texture; textures can store several progressively smaller copies for distance rendering. Here the whole level must be initialised.
texFormatandrtvFormatare internal descriptions of the texture's format.rtvFormatset toDXGI_FORMAT_UNKNOWNmeans "this format cannot be used as a render target", so the GPU cannot clear it directly. That is why the slow path is always taken for BPTC.
Step 3: observe the overflow and the out-of-bounds read
For the 2048x2048x320 BPTC texture, the correct compressed size is 512 * 512 * 320 * 16 = 1,342,177,280 bytes. The initializeContents formula produces 8192 * 2048 * 320 = 5,368,709,120, which wraps to 1,073,741,824 in GLuint. Context::getZeroFilledBuffer allocates this smaller buffer. Image11::loadData then recomputes the correct inputImageSize and issues a memcpy of that length from the undersized source, reading past the end of the allocation.
In plain words:
- The correct size: 2048 pixels wide divided by 4 pixels per block gives 512 blocks across; 2048 tall divided by 4 gives 512 block rows; 320 slices; 16 bytes per block. Multiply those and you get 1,342,177,280 bytes.
- The buggy size: the row pitch is 8192 bytes (512 blocks times 16 bytes), but the height is used as 2048 pixel rows instead of 512 block rows, and the depth is 320. That gives 5,368,709,120, which is larger than a 32-bit unsigned number can hold, so it wraps to 1,073,741,824.
Context::getZeroFilledBufferallocates a buffer of that wrapped, too-small size.Image11::loadDatathen works out the correct size again (1,342,177,280 bytes) and callsmemcpy, a function that copies a given number of bytes from one place to another. It copies far more bytes than the source buffer holds, so it reads past the end of the allocation.
The PoC is launched with:
$ out\asan\chrome.exe --user-data-dir=/tmp/poc /path/to/poc.html 2>/tmp/asan.txt
$ cat /tmp/asan.txt
Line by line:
out\asan\chrome.exeis the ASAN-instrumented browser built earlier.--user-data-dir=/tmp/pocgives it a throwaway profile directory, so it does not touch the normal browser profile./path/to/poc.htmlis the proof-of-concept page to open at startup.2>/tmp/asan.txtredirects the error output (file descriptor 2, where ASAN writes its reports) into a file.cat /tmp/asan.txtprints that file so the report can be read.
The GPU process crashes with a heap-buffer-overflow reported by AddressSanitizer:
=================================================================
==23284==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x12b328cb1800 at pc 0x7ffaa14db36c bp 0x00b7e95fd4a0 sp 0x00b7e95fd4e8
READ of size 1342177280 at 0x12b328cb1800 thread T0
==23284==*** WARNING: Failed to initialize DbgHelp! ***
==23284==*** Most likely this means that the app is already ***
==23284==*** using DbgHelp, possibly with incompatible flags. ***
==23284==*** Due to technical reasons, symbolization might crash ***
==23284==*** or produce wrong results. ***
#0 0x7ffaa14db36b in _asan_memcpy+0x25b (D:\src\chromium\src\out\asan\clang_rt.asan_dynamic-x86_64.dll+0x18004b36b)
#1 0x7ffa968870f3 in angle::LoadCompressedToNative<4,4,1,16> D:\src\chromium\src\third_party\angle\src\image_util\loadimage.inc:389
#2 0x7ffa9696efb4 in rx::Image11::loadData D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\d3d11\Image11.cpp:308
#3 0x7ffa96aa7be1 in rx::TextureD3D::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\renderer\d3d\TextureD3D.cpp:968
#4 0x7ffa9668789c in gl::FramebufferAttachmentObject::initializeContents D:\src\chromium\src\third_party\angle\src\libANGLE\FramebufferAttachment.cpp:365
#5 0x7ffa967a52e8 in gl::Texture::setCompressedSubImage D:\src\chromium\src\third_party\angle\src\libANGLE\Texture.cpp:1494
#6 0x7ffa96611e67 in gl::Context::compressedTexSubImage3D D:\src\chromium\src\third_party\angle\src\libANGLE\Context.cpp:5804
......
What the report shows:
- The first line is the ASAN banner.
heap-buffer-overflowis the class of bug: an access outside the bounds of a buffer allocated on the heap (the general-purpose memory area). READ of size 1342177280says the program tried to read 1,342,177,280 bytes in one go, which is the correct compressed size, from a buffer that is only 1,073,741,824 bytes. The address, program counter, base pointer and stack pointer are machine-level details of where the fault happened.- The
DbgHelpwarning is a note from ASAN that Windows' debugging helper library was already in use, so symbol names in the report might be incomplete. It does not affect the finding. - The numbered lines are the stack trace, the list of function calls that led to the fault, most recent first.
_asan_memcpyis ASAN's checked version ofmemcpy. It was called fromangle::LoadCompressedToNative<4,4,1,16>atloadimage.inc:389, which was called fromrx::Image11::loadDataatImage11.cpp:308, which was called fromrx::TextureD3D::initializeContentsatTextureD3D.cpp:968. Further down, the chain reachesgl::FramebufferAttachmentObject::initializeContents,gl::Texture::setCompressedSubImageand finallygl::Context::compressedTexSubImage3D, the WebGL call the page made.
The full ASAN log is provided in asan.txt.
Root cause
The slow path computes the buffer size as follows:
// third_party/angle/src/libANGLE/renderer/d3d/TextureD3D.cpp
GLuint imageBytes = 0;
ANGLE_CHECK_GL_MATH(contextD3D, formatInfo.computeRowPitch(formatInfo.type, image->getWidth(),
1, 0, &imageBytes));
imageBytes *= image->getHeight() * image->getDepth();
Line by line:
- The comment names the file:
TextureD3D.cppin ANGLE's D3D renderer directory. GLuint imageBytes = 0;declares a 32-bit unsigned integer to hold the size in bytes, starting at zero.ANGLE_CHECK_GL_MATH(...)is a macro that wraps a calculation and checks it for errors. Inside,formatInfo.computeRowPitch(...)calculates how many bytes one row of the image occupies, given the format type, the width, and some other parameters, and stores the result inimageBytes.imageBytes *= image->getHeight() * image->getDepth();multiplies that row size by the height and the depth. This is where the mistake is: for a compressed format, the height should be divided by the block height first, because each row of blocks covers several pixel rows.
For BPTC (4x4 blocks, 16 bytes per block), computeRowPitch correctly returns (width / 4) * 16. The subsequent multiplication, however, uses the raw pixel height rather than the block-row count height / 4, so the result is exactly four times larger than the true compressed image size. The multiplication happens in GLuint arithmetic with no overflow check, so for large textures the product wraps and the allocated buffer is smaller than the data that will be copied into it.
The existing validation does not catch this because it is not the same computation. ValidateCompressedTexImage3D uses computeCompressedImageSize, which properly divides by blockHeight. The two paths therefore disagree on image size for any 3D compressed texture, and nothing reconciles them before the upload.
Impact
The immediate effect is a heap-buffer-overflow read in the GPU process, triggered by any WebGL2 page through standard API calls (texStorage3D followed by a partial compressedTexSubImage3D), with no source modifications required. The report classifies the weakness as an integer overflow and the severity as medium. The conditions are a Windows D3D11 ANGLE backend and a GPU with BPTC (BC6H/BC7) support, which the report describes as standard on all Direct3D 11 hardware.
Fix
The report does not describe a fix. The report does not describe a fix.
Variants to test
- Other block-compressed formats with a block height other than 4, such as ETC or ASTC where supported. A positive result is the same mismatch between the slow-path size and the validated compressed size, with the inflation factor matching the block height.
- 2D compressed textures that reach the same slow path. A positive result is an oversized allocation or an overflow in the same
imageBytescomputation when the height is treated as a pixel count. - Other callers of
computeRowPitchthat multiply the result by a pixel height. A positive result is a second size computation that disagrees withcomputeCompressedImageSizefor compressed formats. - Texture dimensions chosen so the inflated product lands just above 2^32. A positive result is a wrapped
GLuintthat is smaller than the correct compressed size, followed by an out-of-bounds read inLoadCompressedToNative. - The same deferred-initialisation path on other backends, such as the Vulkan or GL backends of ANGLE. A positive result is a zero-fill allocation whose size differs from the validated compressed image size.
Glossary
- ANGLE: the translation layer in Chrome that turns WebGL and OpenGL ES calls into the native graphics API of the platform, Direct3D 11 on Windows.
- API: Application Programming Interface, a defined set of function calls one program may use to talk to another.
- AddressSanitizer (ASAN): a compiler tool that adds checks around memory accesses so out-of-bounds reads and writes are caught and reported.
- args.gn: the configuration file that tells Chromium's build system which options to build with.
- autoninja: Chromium's wrapper around the Ninja build tool, used to build the browser.
- Block-compressed format: a texture format that stores image data in small blocks rather than pixel by pixel, to save memory.
- BPTC: a family of block-compressed texture formats (BC6H and BC7) using 4x4 blocks of 16 bytes each.
- Commit: a recorded change in a source code repository, with an identifier, date and author.
- Compressed texture: a texture stored in a compressed format to save memory.
- computeCompressedImageSize: the validation function that computes the correct compressed image size, dividing by the block height.
- computeRowPitch: the function that computes how many bytes one row of an image occupies.
- CPU: the general-purpose processor; here, where the zero-filled buffer is allocated.
- D3D11 / Direct3D 11: Microsoft's native graphics API on Windows.
- DXGI format: a Microsoft description of a texture format used by Direct3D.
- Fast path / slow path: two ways of doing the same job; the fast path uses the GPU to clear a texture, the slow path builds a zero-filled buffer on the CPU and uploads it.
- GLuint: a 32-bit unsigned integer type used by OpenGL and ANGLE.
- GPU: the graphics processor; here, the process in Chrome that talks to it.
- Heap: the general-purpose memory area where buffers are allocated at runtime.
- Heap-buffer-overflow: a memory access outside the bounds of a buffer allocated on the heap.
- Immutable storage: texture storage whose size and format are fixed at allocation and cannot be changed later.
- Integer overflow: when a calculation produces a number too large for its type, so the value wraps around.
- memcpy: a standard function that copies a given number of bytes from one memory location to another.
- Mip level: one resolution of a texture; textures can store several progressively smaller copies.
- Out-of-bounds read: reading memory outside the bounds of a buffer.
- PoC: proof of concept, a small program that demonstrates a bug.
- Robust resource initialisation: the rule that unwritten parts of a texture must read back as defined values, normally zero.
- Stack trace: the list of function calls that led to a fault, most recent first.
- texStorage3D: the WebGL2 call that allocates immutable storage for a 3D texture.
- compressedTexSubImage3D: the WebGL2 call that uploads a piece of compressed image data into part of a 3D texture.
- Texture: a block of image data stored for use by the graphics card.
- WebGL / WebGL2: the web APIs for 3D graphics in a browser.
- Zero-fill: filling a buffer with zeros.