Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e430d28c authored by Branden Archer's avatar Branden Archer Committed by Gerrit Code Review
Browse files

Merge "Add fuzzer for DepthPhotoProcessor"

parents bb069027 44c331ff
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -22,3 +22,14 @@ cc_fuzz {
        "libcamera_client",
    ],
}

cc_fuzz {
    name: "libcameraservice_depth_processor_fuzzer",
    srcs: [
        "DepthProcessorFuzzer.cpp",
    ],
    shared_libs: [
        "libcameraservice",
    ],
    corpus: ["corpus/*.jpg"],
}
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <array>
#include <vector>

#include <fuzzer/FuzzedDataProvider.h>

#include "common/DepthPhotoProcessor.h"

using namespace android;
using namespace android::camera3;

static const size_t kTestBufferWidth = 640;
static const size_t kTestBufferHeight = 480;
static const size_t kTestBufferDepthSize (kTestBufferWidth * kTestBufferHeight);

void generateDepth16Buffer(const uint8_t* data, size_t size, std::array<uint16_t, kTestBufferDepthSize> *depth16Buffer /*out*/) {
    FuzzedDataProvider dataProvider(data, size);
    for (size_t i = 0; i < depth16Buffer->size(); i++) {
        (*depth16Buffer)[i] = dataProvider.ConsumeIntegral<uint16_t>();
    }
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
    DepthPhotoInputFrame inputFrame;
    // Worst case both depth and confidence maps have the same size as the main color image.
    inputFrame.mMaxJpegSize = inputFrame.mMainJpegSize * 3;

    std::vector<uint8_t> depthPhotoBuffer(inputFrame.mMaxJpegSize);
    size_t actualDepthPhotoSize = 0;

    std::array<uint16_t, kTestBufferDepthSize> depth16Buffer;
    generateDepth16Buffer(data, size, &depth16Buffer);

    inputFrame.mMainJpegBuffer = reinterpret_cast<const char*> (data);
    inputFrame.mMainJpegSize = size;
    inputFrame.mDepthMapBuffer = depth16Buffer.data();
    inputFrame.mDepthMapStride = kTestBufferWidth;
    inputFrame.mDepthMapWidth = kTestBufferWidth;
    inputFrame.mDepthMapHeight = kTestBufferHeight;
    processDepthPhotoFrame(
        inputFrame,
        depthPhotoBuffer.size(),
        depthPhotoBuffer.data(),
        &actualDepthPhotoSize);

  return 0;
}
+1.98 KiB
Loading image diff...
+3.88 KiB
Loading image diff...
+2.78 KiB
Loading image diff...
Loading