Fix a null pointer bug in SkData::copyRange

The documentation for SkData::copyRange allows for a null pointer to be
passed to the buffer argument. However, the current implementation
throws a Segmentation fault if a null pointer is passed. A null pointer
check is added.
fix: check for null pointer

Change-Id: I1b5b67fa161f3b3ddf1fa48093ccdf0380024204
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/498137
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Shekhar Dutta 2022-01-23 17:39:59 +00:00 committed by SkCQ
parent 96071b714f
commit dd1547f582
2 changed files with 4 additions and 1 deletions

View File

@ -74,6 +74,7 @@ JetBrains <*@jetbrains.com>
Vibe Inc <*@vibe.us>
Scene Group Ltd. <*@scenegroup.co>
LG Electronics <*@lge.com>
Shekhar Dutta <sherlockdoyle1904@gmail.com>
# Trusted service accounts.
Recipe roller SA <recipe-mega-autoroller@chops-service-accounts.iam.gserviceaccount.com>

View File

@ -57,7 +57,9 @@ size_t SkData::copyRange(size_t offset, size_t length, void* buffer) const {
}
SkASSERT(length > 0);
memcpy(buffer, this->bytes() + offset, length);
if (buffer) {
memcpy(buffer, this->bytes() + offset, length);
}
return length;
}