[libFuzzer] Fix off-by-one error in ApplyDictionaryEntry
authorFabian Meumertzheim <meumertzheim@code-intelligence.com>
Fri, 30 Apr 2021 16:16:43 +0000 (09:16 -0700)
committerMatt Morehouse <mascasa@google.com>
Mon, 3 May 2021 17:37:44 +0000 (10:37 -0700)
commit62e4dca94e25668c9f70abc7e524328fd5c6d5c9
treef982036e2a7e5ebadbb52b85afa4f984fac2a6b9
parent89a94be16b01154e421d86d2e15e48d87b8d07db
[libFuzzer] Fix off-by-one error in ApplyDictionaryEntry

In the overwrite branch of MutationDispatcher::ApplyDictionaryEntry in
FuzzerMutate.cpp, the index Idx at which W.size() bytes are overwritten
with the word W is chosen uniformly at random in the interval
[0, Size - W.size()). This means that Idx + W.size() will always be
strictly less than Size, i.e., the last byte of the current unit will
never be overwritten.

This is fixed by adding 1 to the exclusive upper bound.

Addresses https://bugs.llvm.org/show_bug.cgi?id=49989.

Reviewed By: morehouse

Differential Revision: https://reviews.llvm.org/D101625
compiler-rt/lib/fuzzer/FuzzerMutate.cpp