Repository: google/flatbuffers
File: include/flatbuffers/verifier.h (C/C++)

Code before:
 *
 * 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.
 */

#ifndef FLATBUFFERS_VERIFIER_H_
#define FLATBUFFERS_VERIFIER_H_

#include "flatbuffers/base.h"
#include "flatbuffers/vector.h"

namespace flatbuffers {

// Helper class to verify the integrity of a FlatBuffer
class Verifier FLATBUFFERS_FINAL_CLASS {
 public:
  struct Options {
    uoffset_t max_depth = 64;
    uoffset_t max_tables = 1000000;
    bool check_alignment = true;
    bool check_nested_flatbuffers = true;
  };
  Verifier(const uint8_t *const buf, const size_t buf_len, Options opts)
      : Verifier(buf, buf_len, opts.max_depth, opts.max_tables,
                 opts.check_alignment, opts.check_nested_flatbuffers) {}

  Verifier(const uint8_t *const buf, const size_t buf_len,
           const uoffset_t _max_depth = 64,
           const uoffset_t _max_tables = 1000000,
           const bool _check_alignment = true,
           const bool _check_nested_flatbuffers = true)
      : buf_(buf),
        size_(buf_len),
        max_depth_(_max_depth),
        max_tables_(_max_tables),
        check_alignment_(_check_alignment),
        check_nested_flatbuffers_(_check_nested_flatbuffers),
        upper_bound_(0),
        depth_(0),
        num_tables_(0),
        flex_reuse_tracker_(nullptr) {
    FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
  }

  // Central location where any verification failures register.
  bool Check(const bool ok) const {
    // clang-format off
    #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE

Review comment (suggestion):
This should be: 
`const Options& options = Options{}`

Code after:
 *
 * 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.
 */

#ifndef FLATBUFFERS_VERIFIER_H_
#define FLATBUFFERS_VERIFIER_H_

#include "flatbuffers/base.h"
#include "flatbuffers/vector.h"

namespace flatbuffers {

// Helper class to verify the integrity of a FlatBuffer
class Verifier FLATBUFFERS_FINAL_CLASS {
 public:
  struct Options {
    // The maximum nesting of tables and vectors before we call it invalid.
    uoffset_t max_depth = 64;
    // The maximum number of tables we will verify before we call it invalid.
    uoffset_t max_tables = 1000000;
    // If true, verify all data is aligned.
    bool check_alignment = true;
    // If true, run verifier on nested flatbuffers
    bool check_nested_flatbuffers = true;

    // Manually implemented constructors for compilers that can't figure it out.
    Options() = default;
    Options(uoffset_t d, uoffset_t t, bool a, bool n)
        : max_depth(d),
          max_tables(t),
          check_alignment(a),
          check_nested_flatbuffers(n) {}
  };

  Verifier(const uint8_t *const buf, const size_t buf_len, const Options opts)
      : buf_(buf),
        size_(buf_len),
        opts_(opts),
        upper_bound_(0),
        depth_(0),
        num_tables_(0),
        flex_reuse_tracker_(nullptr) {
    FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
  }

  // Deprecated API, please construct with Verifier::Options.
  Verifier(const uint8_t *const buf, const size_t buf_len,