Skip to content

Commit bcb93a3

Browse files
committed
[libFuzzer] Make MutateWithMask work when the Mask is shorter than the input.
Summary: Before this change, MutateWithMask used to assert that Mask should be of sufficient length (>= Size of the input). However, in real cases we may have inputs that are longer than the Mask they have inherited from the based inputs. Reviewers: kcc, morehouse Reviewed By: kcc Subscribers: delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D60571 llvm-svn: 358207
1 parent 3e58f94 commit bcb93a3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler-rt/lib/fuzzer/FuzzerMutate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ size_t MutationDispatcher::MutateImpl(uint8_t *Data, size_t Size,
529529
size_t MutationDispatcher::MutateWithMask(uint8_t *Data, size_t Size,
530530
size_t MaxSize,
531531
const Vector<uint8_t> &Mask) {
532-
assert(Size <= Mask.size());
532+
size_t MaskedSize = std::min(Size, Mask.size());
533533
// * Copy the worthy bytes into a temporary array T
534534
// * Mutate T
535535
// * Copy T back.
@@ -538,7 +538,7 @@ size_t MutationDispatcher::MutateWithMask(uint8_t *Data, size_t Size,
538538
if (T.size() < Size)
539539
T.resize(Size);
540540
size_t OneBits = 0;
541-
for (size_t I = 0; I < Size; I++)
541+
for (size_t I = 0; I < MaskedSize; I++)
542542
if (Mask[I])
543543
T[OneBits++] = Data[I];
544544

@@ -548,7 +548,7 @@ size_t MutationDispatcher::MutateWithMask(uint8_t *Data, size_t Size,
548548
assert(NewSize <= OneBits);
549549
(void)NewSize;
550550
// Even if NewSize < OneBits we still use all OneBits bytes.
551-
for (size_t I = 0, J = 0; I < Size; I++)
551+
for (size_t I = 0, J = 0; I < MaskedSize; I++)
552552
if (Mask[I])
553553
Data[I] = T[J++];
554554
return Size;

0 commit comments

Comments
 (0)