Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: testing/libfuzzer/fuzzers/skia_color_space_fuzzer.cc

Issue 2827573003: Skia color space fuzzer: use a locally defined Hash function (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <cstddef> 5 #include <cstddef>
6 #include <cstdint> 6 #include <cstdint>
7 #include <random> 7 #include <random>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_piece.h"
11 #include "testing/libfuzzer/fuzzers/color_space_data.h" 10 #include "testing/libfuzzer/fuzzers/color_space_data.h"
12 #include "third_party/skia/include/core/SkColorSpace.h" 11 #include "third_party/skia/include/core/SkColorSpace.h"
13 #include "third_party/skia/include/core/SkColorSpaceXform.h" 12 #include "third_party/skia/include/core/SkColorSpaceXform.h"
14 13
15 static constexpr size_t kPixels = 2048 / 4; 14 static constexpr size_t kPixels = 2048 / 4;
16 15
17 static uint32_t pixels[kPixels * 4]; 16 static uint32_t pixels[kPixels * 4];
18 17
19 static void GeneratePixels(size_t hash) { 18 static void GeneratePixels(size_t hash) {
20 static std::uniform_int_distribution<uint32_t> uniform(0u, ~0u); 19 static std::uniform_int_distribution<uint32_t> uniform(0u, ~0u);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 SkColorSpace::Gamut::kAdobeRGB_Gamut), 55 SkColorSpace::Gamut::kAdobeRGB_Gamut),
57 SkColorSpace::MakeRGB( 56 SkColorSpace::MakeRGB(
58 SkColorSpace::RenderTargetGamma::kSRGB_RenderTargetGamma, 57 SkColorSpace::RenderTargetGamma::kSRGB_RenderTargetGamma,
59 SkColorSpace::Gamut::kDCIP3_D65_Gamut), 58 SkColorSpace::Gamut::kDCIP3_D65_Gamut),
60 SkColorSpace::MakeSRGB(), 59 SkColorSpace::MakeSRGB(),
61 }; 60 };
62 61
63 return profiles[hash & 7]; 62 return profiles[hash & 7];
64 } 63 }
65 64
66 inline size_t Hash(const char* data, size_t size) { 65 inline size_t Hash(const char* data, size_t size, size_t hash = ~0) {
67 return base::StringPieceHash()(base::StringPiece(data, size)); 66 for (size_t i = 0; i < size; ++i)
67 hash = hash * 131 + *data++;
68 return hash;
68 } 69 }
69 70
70 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
71 constexpr size_t kSizeLimit = 4 * 1024 * 1024; 72 constexpr size_t kSizeLimit = 4 * 1024 * 1024;
72 if (size < 128 || size > kSizeLimit) 73 if (size < 128 || size > kSizeLimit)
73 return 0; 74 return 0;
74 75
75 test = SkColorSpace::MakeICC(data, size); 76 test = SkColorSpace::MakeICC(data, size);
76 if (!test.get()) 77 if (!test.get())
77 return 0; 78 return 0;
78 79
79 const size_t hash = Hash(reinterpret_cast<const char*>(data), size); 80 const size_t hash = Hash(reinterpret_cast<const char*>(data), size);
80 srgb = SelectProfile(hash); 81 srgb = SelectProfile(hash);
81 GeneratePixels(hash); 82 GeneratePixels(hash);
82 83
83 ColorTransform(hash, true); 84 ColorTransform(hash, true);
84 ColorTransform(hash, false); 85 ColorTransform(hash, false);
85 86
86 test.reset(); 87 test.reset();
87 srgb.reset(); 88 srgb.reset();
88 return 0; 89 return 0;
89 } 90 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698