Jun Choi | 6d30c4a | 2017-12-09 01:10:32 | [diff] [blame] | 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 <stdint.h> |
| 6 | #include <algorithm> |
| 7 | |
Jun Choi | 9f1446c0 | 2017-12-21 23:33:27 | [diff] [blame] | 8 | #include "components/cbor/cbor_reader.h" // nogncheck |
| 9 | #include "components/cbor/cbor_writer.h" // nogncheck |
Jun Choi | 6d30c4a | 2017-12-09 01:10:32 | [diff] [blame] | 10 | |
Jun Choi | 9f1446c0 | 2017-12-21 23:33:27 | [diff] [blame] | 11 | namespace cbor { |
Jun Choi | 6d30c4a | 2017-12-09 01:10:32 | [diff] [blame] | 12 | |
| 13 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 14 | std::vector<uint8_t> input(data, data + size); |
| 15 | base::Optional<CBORValue> cbor = CBORReader::Read(input); |
| 16 | |
| 17 | if (cbor.has_value()) { |
| 18 | base::Optional<std::vector<uint8_t>> serialized_cbor = |
| 19 | CBORWriter::Write(cbor.value()); |
| 20 | CHECK(serialized_cbor.has_value()); |
| 21 | if (serialized_cbor.has_value()) { |
| 22 | CHECK(serialized_cbor.value().size() == input.size()); |
| 23 | CHECK(memcmp(serialized_cbor.value().data(), input.data(), |
| 24 | input.size()) == 0); |
| 25 | } |
| 26 | } |
| 27 | return 0; |
| 28 | } |
| 29 | |
Jun Choi | 9f1446c0 | 2017-12-21 23:33:27 | [diff] [blame] | 30 | } // namespace cbor |