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

Side by Side Diff: third_party/qcms/qcms_color_space_fuzzer.cc

Issue 2807083002: Add LLVM fuzzer: QCMS color space and color transform (Closed)
Patch Set: Review comments: Move to root BUILD.gn file. 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 | « third_party/qcms/DEPS ('k') | 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <cstddef>
6 #include <cstdint>
7 #include <random>
8
9 #include "base/logging.h"
10 #include "base/strings/string_piece.h"
11 #include "testing/libfuzzer/fuzzers/color_space_data.h"
12 #include "third_party/qcms/src/qcms.h"
13
14 static constexpr size_t kPixels = 2048 / 4;
15
16 static uint32_t pixels[kPixels];
17
18 static void GeneratePixels(size_t hash) {
19 static std::uniform_int_distribution<uint32_t> uniform(0u, ~0u);
20
21 std::mt19937_64 random(hash);
22 for (size_t i = 0; i < arraysize(pixels); ++i)
23 pixels[i] = uniform(random);
24 }
25
26 static qcms_profile* test;
27 static qcms_profile* srgb;
28
29 static void ColorTransform(bool input) {
30 if (!test)
31 return;
32
33 const qcms_intent intent = QCMS_INTENT_DEFAULT;
34 const qcms_data_type format = QCMS_DATA_RGBA_8;
35
36 auto transform =
dcheng 2017/04/12 07:19:23 Nit: auto*
Noel Gordon 2017/04/12 12:09:47 Done.
37 input ? qcms_transform_create(test, format, srgb, format, intent)
38 : qcms_transform_create(srgb, format, test, format, intent);
39 if (!transform)
40 return;
41
42 static uint32_t output[kPixels];
43
44 qcms_transform_data(transform, pixels, output, kPixels);
45 qcms_transform_release(transform);
46 }
47
48 static qcms_profile* SelectProfile(size_t hash) {
49 static qcms_profile* profiles[4] = {
50 qcms_profile_from_memory(kSRGBData, arraysize(kSRGBData)),
51 qcms_profile_from_memory(kSRGBPara, arraysize(kSRGBPara)),
52 qcms_profile_from_memory(kAdobeData, arraysize(kAdobeData)),
53 qcms_profile_sRGB(),
54 };
55
56 return profiles[hash & 3];
57 }
58
59 inline size_t Hash(const char* data, size_t size) {
60 return base::StringPieceHash()(base::StringPiece(data, size));
61 }
62
63 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
64 constexpr size_t kSizeLimit = 4 * 1024 * 1024;
65 if (size < 128 || size > kSizeLimit)
66 return 0;
67
68 test = qcms_profile_from_memory(data, size);
69 if (!test)
70 return 0;
71
72 const size_t hash = Hash(reinterpret_cast<const char*>(data), size);
dcheng 2017/04/12 07:19:23 How about just running this through base::SHA1Hash
Noel Gordon 2017/04/12 12:09:47 Too slow: need a good and fast hash.
dcheng 2017/04/12 20:21:10 Hmm... how about just use one byte of the test inp
73 srgb = SelectProfile(hash);
74 GeneratePixels(hash);
75
76 qcms_profile_precache_output_transform(srgb);
77 ColorTransform(true);
78
79 qcms_profile_precache_output_transform(test);
80 ColorTransform(false);
81
82 qcms_profile_release(test);
83 return 0;
84 }
OLDNEW
« no previous file with comments | « third_party/qcms/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698