Coverage Report

Created: 2026-05-16 06:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zip_fuzz.cpp
Line
Count
Source
1
/* Copyright 2026 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
#include <stdint.h>
14
#include <stdlib.h>
15
#include <string.h>
16
17
#include "OgreArchive.h"
18
#include "OgreArchiveManager.h"
19
#include "OgreLogManager.h"
20
#include "OgreZip.h"
21
#include "OgreResourceGroupManager.h"
22
23
static bool g_initialized = false;
24
static Ogre::EmbeddedZipArchiveFactory* g_zipFactory = nullptr;
25
26
3.75k
static void global_init() {
27
3.75k
  if (g_initialized)
28
3.75k
    return;
29
30
1
  auto *logMgr = new Ogre::LogManager();
31
1
  logMgr->createLog("fuzz_zip.log", true, false, true);
32
1
  logMgr->setMinLogLevel(Ogre::LML_CRITICAL);
33
34
1
  new Ogre::ResourceGroupManager();
35
1
  new Ogre::ArchiveManager();
36
  
37
1
  g_zipFactory = new Ogre::EmbeddedZipArchiveFactory();
38
1
  Ogre::ArchiveManager::getSingleton().addArchiveFactory(g_zipFactory);
39
40
1
  g_initialized = true;
41
1
}
42
43
3.75k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
44
3.75k
  if (size < 1)
45
0
    return 0;
46
47
3.75k
  global_init();
48
49
3.75k
  Ogre::String name = "fuzz.zip";
50
3.75k
  g_zipFactory->addEmbbeddedFile(name, data, size, nullptr);
51
52
3.75k
  Ogre::Archive *arch = g_zipFactory->createInstance(name, true);
53
3.75k
  if (arch) {
54
3.75k
    try {
55
3.75k
      arch->load();
56
      
57
      // List files
58
3.75k
      Ogre::StringVectorPtr files = arch->list();
59
      
60
      // Try to open first few files
61
3.75k
      int count = 0;
62
3.75k
      for (auto &f : *files) {
63
3.34k
        if (count++ > 10) break;
64
3.34k
        try {
65
3.34k
          Ogre::DataStreamPtr stream = arch->open(f);
66
3.34k
          if (stream) {
67
            // Read some data
68
637
            char buf[1024];
69
637
            stream->read(buf, std::min((size_t)1024, (size_t)stream->size()));
70
637
          }
71
3.34k
        } catch (...) {}
72
3.34k
      }
73
      
74
3.75k
      arch->unload();
75
3.75k
    } catch (...) {}
76
3.75k
    g_zipFactory->destroyInstance(arch);
77
3.75k
  }
78
79
3.75k
  return 0;
80
3.75k
}