mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
Skia: Validate allocation size in GrBufferAllocPool using SkSafeMath.
Upstream port of commit 7469a9341afab19271b8ef07af5c16a0f2c4ccc1
This commit is contained in:
parent
c0ae9a7b5b
commit
32c0424845
1 changed files with 8 additions and 3 deletions
|
|
@ -152,13 +152,18 @@ void* GrBufferAllocPool::makeSpace(size_t size,
|
|||
BufferBlock& back = fBlocks.back();
|
||||
size_t usedBytes = back.fBuffer->gpuMemorySize() - back.fBytesFree;
|
||||
size_t pad = GrSizeAlignUpPad(usedBytes, alignment);
|
||||
if ((size + pad) <= back.fBytesFree) {
|
||||
SkSafeMath safeMath;
|
||||
size_t alignedSize = safeMath.add(pad, size);
|
||||
if (!safeMath.ok()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (alignedSize <= back.fBytesFree) {
|
||||
memset((void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes), 0, pad);
|
||||
usedBytes += pad;
|
||||
*offset = usedBytes;
|
||||
*buffer = back.fBuffer;
|
||||
back.fBytesFree -= size + pad;
|
||||
fBytesInUse += size + pad;
|
||||
back.fBytesFree -= alignedSize;
|
||||
fBytesInUse += alignedSize;
|
||||
VALIDATE();
|
||||
return (void*)(reinterpret_cast<intptr_t>(fBufferPtr) + usedBytes);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue