aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/openexr/openexr_exrheader_fuzzer.cc
blob: c771059149bb7fdb03dc210121f98a77ae79f30b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Copyright 2020 Google LLC
//
// 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 "ImfNamespace.h"
#include <ImfBoxAttribute.h>
#include <ImfChannelListAttribute.h>
#include <ImfChromaticitiesAttribute.h>
#include <ImfCompressionAttribute.h>
#include <ImfDoubleAttribute.h>
#include <ImfEnvmapAttribute.h>
#include <ImfFloatAttribute.h>
#include <ImfHeader.h>
#include <ImfIntAttribute.h>
#include <ImfKeyCodeAttribute.h>
#include <ImfLineOrderAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfMultiPartInputFile.h>
#include <ImfPreviewImageAttribute.h>
#include <ImfRationalAttribute.h>
#include <ImfStdIO.h>
#include <ImfStringAttribute.h>
#include <ImfStringVectorAttribute.h>
#include <ImfTileDescriptionAttribute.h>
#include <ImfTimeCodeAttribute.h>
#include <ImfVecAttribute.h>
#include <ImfVersion.h>

#include <iomanip>
#include <iostream>

using namespace OPENEXR_IMF_NAMESPACE;
using namespace std;

void dumpTimeCode(TimeCode tc) {
  tc.hours();
  tc.minutes();
  tc.seconds();
  tc.frame();

  tc.dropFrame();
  tc.colorFrame();
  tc.fieldPhase();
  tc.bgf0();
  tc.bgf1();
  tc.bgf2();
  tc.userData();
}

void dumpChannelList(const ChannelList &cl) {
  for (ChannelList::ConstIterator i = cl.begin(); i != cl.end(); ++i) {
    i.name();
    i.channel();
  }
}

void dumpInfo(IStream &is) {
  MultiPartInputFile in(is, 0);
  int parts = in.parts();

  getVersion(in.version());
  getFlags(in.version());

  for (int p = 0; p < parts; ++p) {
    const Header &h = in.header(p);

    if (parts != 1) {
      in.partComplete(p);
    }

    for (Header::ConstIterator i = h.begin(); i != h.end(); ++i) {
      const Attribute *a = &i.attribute();
      i.name();
      a->typeName();

      if (const Box2iAttribute *ta = dynamic_cast<const Box2iAttribute *>(a)) {
        ta->value();
      }

      else if (const Box2fAttribute *ta =
                   dynamic_cast<const Box2fAttribute *>(a)) {
        ta->value();
      } else if (const ChannelListAttribute *ta =
                     dynamic_cast<const ChannelListAttribute *>(a)) {
        dumpChannelList(ta->value());
      } else if (const ChromaticitiesAttribute *ta =
                     dynamic_cast<const ChromaticitiesAttribute *>(a)) {
        ta->value();
      } else if (const DoubleAttribute *ta =
                     dynamic_cast<const DoubleAttribute *>(a)) {
        ta->value();
      } else if (const FloatAttribute *ta =
                     dynamic_cast<const FloatAttribute *>(a)) {
        ta->value();
      } else if (const IntAttribute *ta =
                     dynamic_cast<const IntAttribute *>(a)) {
        ta->value();
      } else if (const KeyCodeAttribute *ta =
                     dynamic_cast<const KeyCodeAttribute *>(a)) {
        ta->value().filmMfcCode();
        ta->value().filmType();
        ta->value().prefix();
        ta->value().count();
        ta->value().perfOffset();
        ta->value().perfsPerFrame();
        ta->value().perfsPerCount();
      } else if (const M33fAttribute *ta =
                     dynamic_cast<const M33fAttribute *>(a)) {
        ta->value();
      } else if (const M44fAttribute *ta =
                     dynamic_cast<const M44fAttribute *>(a)) {
        ta->value();
      } else if (const PreviewImageAttribute *ta =
                     dynamic_cast<const PreviewImageAttribute *>(a)) {
        ta->value().width();
        ta->value().height();
      } else if (const StringAttribute *ta =
                     dynamic_cast<const StringAttribute *>(a)) {
        ta->value();
      } else if (const StringVectorAttribute *ta =
                     dynamic_cast<const StringVectorAttribute *>(a)) {
        for (StringVector::const_iterator i = ta->value().begin();
             i != ta->value().end(); ++i) {
          *i;
        }
      } else if (const RationalAttribute *ta =
                     dynamic_cast<const RationalAttribute *>(a)) {
        ta->value();
      } else if (const TileDescriptionAttribute *ta =
                     dynamic_cast<const TileDescriptionAttribute *>(a)) {
        ta->value();

      } else if (const TimeCodeAttribute *ta =
                     dynamic_cast<const TimeCodeAttribute *>(a)) {
        dumpTimeCode(ta->value());
      } else if (const V2iAttribute *ta =
                     dynamic_cast<const V2iAttribute *>(a)) {
        ta->value();
      } else if (const V2fAttribute *ta =
                     dynamic_cast<const V2fAttribute *>(a)) {
        ta->value();
      } else if (const V3iAttribute *ta =
                     dynamic_cast<const V3iAttribute *>(a)) {
        ta->value();
      } else if (const V3fAttribute *ta =
                     dynamic_cast<const V3fAttribute *>(a)) {
        ta->value();
      }
    }
  }
}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {

  const std::string s(reinterpret_cast<const char *>(data), size);
  StdISStream is;
  is.str(s);

  try {
    dumpInfo(is);
  } catch (...) {
    ;
  }

  return 0;
}