Bug 1743767 - Tighten bounds and add asserts for row-by-row ReadPixels. r=gfx-reviewers,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D144900
This commit is contained in:
Kelsey Gilbert 2022-05-12 03:23:40 +00:00
Родитель 29bfef65cb
Коммит 4416195118
1 изменённых файлов: 13 добавлений и 6 удалений

Просмотреть файл

@ -1187,13 +1187,20 @@ webgl::ReadPixelsResult WebGLContext::ReadPixelsImpl(
desc2.srcOffset = {readX, readY}; desc2.srcOffset = {readX, readY};
desc2.size = {rwSize.x, 1}; desc2.size = {rwSize.x, 1};
auto row = dest + writeX * explicitPacking.metrics.bytesPerPixel; const auto skipBytes = writeX * explicitPacking.metrics.bytesPerPixel;
row += writeY * rowStride; const auto usedRowBytes = rwSize.x * explicitPacking.metrics.bytesPerPixel;
for (const auto j : IntegerRange(size.y)) { for (const auto j : IntegerRange(rwSize.y)) {
desc2.srcOffset.y = readY + j; desc2.srcOffset.y = readY + j;
DoReadPixelsAndConvert(srcFormat->format, desc2, row, bytesNeeded, const auto destWriteBegin = dest + skipBytes + (writeY + j) * rowStride;
rowStride); MOZ_RELEASE_ASSERT(dest <= destWriteBegin);
row += rowStride; MOZ_RELEASE_ASSERT(destWriteBegin <= dest + availBytes);
const auto destWriteEnd = destWriteBegin + usedRowBytes;
MOZ_RELEASE_ASSERT(dest <= destWriteEnd);
MOZ_RELEASE_ASSERT(destWriteEnd <= dest + availBytes);
DoReadPixelsAndConvert(srcFormat->format, desc2, destWriteBegin,
destWriteEnd - destWriteBegin, rowStride);
} }
} }