Coverage Report

Created: 2025-08-03 06:56

/src/stream_fuzz.cpp
Line
Count
Source (jump to first uncovered line)
1
/* Copyright 2023 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
13
/*
14
 * The main idea behind this fuzzer is the generate arbitrary stack traces
15
 * by way of recursive funcitons, and then using various calls to libunwind
16
 * apis arbitrarily.
17
 */
18
#include <stdio.h>
19
#include <stdlib.h>
20
#include <unistd.h>
21
22
#include <iostream>
23
#include <string>
24
25
#include "OgreException.h"
26
#include "OgreFileSystem.h"
27
#include "OgreStreamSerialiser.h"
28
#include "OgreVector.h"
29
30
272
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31
272
  char filename[256];
32
272
  sprintf(filename, "/tmp/libfuzzer.%d", getpid());
33
34
272
  FILE *fp = fopen(filename, "wb");
35
272
  if (!fp) {
36
0
    return 0;
37
0
  }
38
272
  fwrite(data, size, 1, fp);
39
272
  fclose(fp);
40
41
272
  Ogre::String fileName = filename;
42
43
272
  Ogre::FileSystemArchiveFactory factory;
44
272
  Ogre::Archive *arch = factory.createInstance("/tmp/", false);
45
272
  arch->load();
46
47
272
  Ogre::DataStreamPtr stream = arch->open(fileName);
48
272
  Ogre::StreamSerialiser serialiser(stream);
49
272
  try {
50
272
    const Ogre::StreamSerialiser::Chunk *c = serialiser.readChunkBegin();
51
52
272
    Ogre::Vector3 dest;
53
272
    serialiser.read(&dest, 1);
54
272
  } catch (Ogre::InvalidStateException) {
55
272
  }
56
272
  factory.destroyInstance(arch);
57
272
  unlink(filename);
58
59
272
  return 0;
60
272
}