Skip to content

Commit 35c64f6

Browse files
herbderbySkia Commit-Bot
authored andcommitted
Only checksum and query a valid descriptor
Bug: oss-fuzz:19549 Change-Id: I941470cfa31c46b3e92cf53877efd2da8d181c01 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/260896 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
1 parent 6093145 commit 35c64f6

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

fuzz/FuzzSkDescriptor.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ DEF_FUZZ(SkDescriptor, fuzz) {
1818
return;
1919
}
2020

21-
size_t len = SkDescriptor::ComputeOverhead(numEntries);
22-
auto desc = SkDescriptor::Alloc(len);
21+
size_t overhead = SkDescriptor::ComputeOverhead(numEntries);
22+
size_t data;
23+
fuzz->nextRange(&data, 0, 500);
24+
auto desc = SkDescriptor::Alloc(overhead + data);
2325
for (int32_t i = 0; i<numEntries && !fuzz->exhausted(); i++) {
2426
uint32_t tag;
2527
fuzz->next(&tag);
@@ -36,19 +38,15 @@ DEF_FUZZ(SkDescriptor, fuzz) {
3638
}
3739

3840
uint8_t choice;
39-
fuzz->nextRange(&choice, 0, 2);
41+
fuzz->nextRange(&choice, 0, 1);
4042
switch(choice) {
41-
case 0: { // use nullptr
42-
desc->addEntry(tag, length, nullptr);
43-
break;
44-
}
45-
case 1: { // use SkScalerContextRec
43+
case 0: { // use SkScalerContextRec
4644
SkScalerContextRec rec;
4745
fuzz->next(&rec);
4846
desc->addEntry(tag, sizeof(rec), &rec);
4947
break;
5048
}
51-
case 2: { // use arbitrary data
49+
case 1: { // use arbitrary data
5250
if (fuzz->remaining() < length) {
5351
// Can't initialize all that we requested, so bail out.
5452
return;
@@ -67,12 +65,13 @@ DEF_FUZZ(SkDescriptor, fuzz) {
6765

6866
// Exercise the API to make sure we don't step out of bounds, etc.
6967

70-
desc->computeChecksum();
71-
desc->isValid();
68+
if (desc->isValid()) {
69+
desc->computeChecksum();
7270

73-
uint32_t tagToFind;
74-
fuzz->next(&tagToFind);
71+
uint32_t tagToFind;
72+
fuzz->next(&tagToFind);
7573

76-
uint32_t ignore;
77-
desc->findEntry(tagToFind, &ignore);
74+
uint32_t ignore;
75+
desc->findEntry(tagToFind, &ignore);
76+
}
7877
}

0 commit comments

Comments
 (0)