Overflow in TextureStorage11::setData can cause memory-safety bug
- Fixed in 2 months
- Paid in 3 months
- Disclosed after 2 months
TextureStorage11::setData (gfx\angle\src\libGLESv2\renderer\d3d\d3d11\TextureStorage11.cpp) can experience an overflow if its caller specifies a destBox or image argument with unusually-large dimensions. On overflow, setData allocates a buffer that is far too small, then loads an image into it, thus writing memory it does not own.
It is unclear whether checks elsewhere that limit the size of images, such as those in WebGL2Content::TexImage3D (dom\canvas\WebGL2ContentTextures.cpp), make TextureStorage11::setData safe in practice. In any case, it is safer for each function or object to protect itself from insecure operation than for a function in a deeper layer to rely upon checks made by a function closer to the security perimeter.
Details: Using ints and UINTs, setData computes the quantity:
outputPixelSize * width * height * depth
where outputPixelSize is the number of bytes per pixel (probably always 4), and width, height, and depth are derived from either the destBox argument (if specified) or else the |image| argument:
461: gl::Error TextureStorage11::setData(const gl::ImageIndex &index, Image *image, const gl::Box *destBox, GLenum type,
462: const gl::PixelUnpackState &unpack, const uint8_t *pixelData)
...
485: int width = destBox ? destBox->width : static_cast<int>(image->getWidth());
486: int height = destBox ? destBox->height : static_cast<int>(image->getHeight());
487: int depth = destBox ? destBox->depth : static_cast<int>(image->getDepth());
488: UINT srcRowPitch = internalFormatInfo.computeRowPitch(type, width, unpack.alignment);
489: UINT srcDepthPitch = internalFormatInfo.computeDepthPitch(type, width, height, unpack.alignment);
490:
491: const d3d11::TextureFormat &d3d11Format = d3d11::GetTextureFormatInfo(image->getInternalFormat());
492: const d3d11::DXGIFormat &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(d3d11Format.texFormat);
493:
494: size_t outputPixelSize = dxgiFormatInfo.pixelBytes;
495:
496: UINT bufferRowPitch = outputPixelSize * width;
497: UINT bufferDepthPitch = bufferRowPitch * height;
498:
499: MemoryBuffer conversionBuffer;
500: if (!conversionBuffer.resize(bufferDepthPitch * depth))
501: {
502: return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal buffer.");
503: }
503:
505: // TODO: fast path
506: LoadImageFunction loadFunction = d3d11Format.loadFunctions.at(type);
507: loadFunction(width, height, depth,
508: pixelData, srcRowPitch, srcDepthPitch,
509: conversionBuffer.data(), bufferRowPitch, bufferDepthPitch);
...
Thus, a 3D image as small as 1024x1024x1025x32bpp or a 2D image as small as 32768x32769x32bpp could cause an overflow.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A high-severity memory corruption bug in Graphics: CanvasWebGL. Mozilla made it public on 6 October 2015 as CVE-2015-7198.
About 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.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.