1 // Copyright 2018 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <iostream> 6 #include <memory> 7 #include <vector> 8 9 #include "bsdiff/bspatch.h" 10 #include "bsdiff/memory_file.h" 11 #include "bsdiff/sink_file.h" 12 13 namespace { 14 15 void FuzzBspatch(const uint8_t* data, size_t size) { 16 const size_t kBufferSize = 1024; 17 std::vector<uint8_t> source_buffer(kBufferSize); 18 std::unique_ptr<bsdiff::FileInterface> source( 19 new bsdiff::MemoryFile(source_buffer.data(), source_buffer.size())); 20 std::unique_ptr<bsdiff::FileInterface> target(new bsdiff::SinkFile( 21 [](const uint8_t* data, size_t size) { return size; })); 22 bsdiff::bspatch(source, target, data, size); 23 } 24 25 struct Environment { 26 Environment() { 27 // To turn off logging for bsdiff library. 28 std::cerr.setstate(std::ios_base::failbit); 29 } 30 }; 31 32 } // namespace 33 34 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 35 static Environment env; 36 FuzzBspatch(data, size); 37 return 0; 38 } 39