transfer_cache_fuzzer.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2018 The Chromium 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. #include <stddef.h>
  5. #include <stdint.h>
  6. #include "cc/paint/paint_op_buffer.h"
  7. #include "cc/paint/raw_memory_transfer_cache_entry.h"
  8. #include "cc/test/transfer_cache_test_helper.h"
  9. #include "components/viz/test/test_context_provider.h"
  10. #include "third_party/skia/include/core/SkSurface.h"
  11. #include "third_party/skia/include/gpu/GrDirectContext.h"
  12. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  13. if (size < 4)
  14. return 0;
  15. scoped_refptr<viz::TestContextProvider> context_provider =
  16. viz::TestContextProvider::Create();
  17. context_provider->BindToCurrentThread();
  18. cc::TransferCacheEntryType entry_type =
  19. static_cast<cc::TransferCacheEntryType>(data[0]);
  20. std::unique_ptr<cc::ServiceTransferCacheEntry> entry =
  21. cc::ServiceTransferCacheEntry::Create(entry_type);
  22. if (!entry)
  23. return 0;
  24. // Align data.
  25. base::span<const uint8_t> span(&data[4], size - 4);
  26. if (!entry->Deserialize(context_provider->GrContext(), span))
  27. return 0;
  28. // TODO(enne): consider running Serialize() here to fuzz that codepath
  29. // for bugs. However, that requires setting up a real context with
  30. // a raster interface that supports gl operations and that has a
  31. // TransferCacheTestHelper in it so the innards of client and service
  32. // are accessible.
  33. return 0;
  34. }