Consolidate various GetInteger() functions in fuzzers.

Move them in pdfium_fuzzer_util.h, and add some parenthesis inside the
function to better define operator precedence.

Change-Id: Ia712def97a17e324c0d3a926dac3de746e9c6db4
Reviewed-on: https://pdfium-review.googlesource.com/c/50232
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/testing/fuzzers/BUILD.gn b/testing/fuzzers/BUILD.gn
index ba930f9..5deda55 100644
--- a/testing/fuzzers/BUILD.gn
+++ b/testing/fuzzers/BUILD.gn
@@ -67,6 +67,15 @@
   }
 }
 
+jumbo_source_set("utils") {
+  sources = [
+    "pdfium_fuzzer_util.cc",
+    "pdfium_fuzzer_util.h",
+  ]
+
+  testonly = true
+}
+
 template("pdfium_public_fuzzer") {
   jumbo_source_set(target_name) {
     sources = invoker.sources + [
@@ -291,6 +300,7 @@
     "pdf_codec_fax_fuzzer.cc",
   ]
   deps = [
+    ":utils",
     "../../core/fxcodec",
   ]
 }
@@ -310,6 +320,7 @@
     "pdf_codec_jbig2_fuzzer.cc",
   ]
   deps = [
+    ":utils",
     "../../core/fpdfapi/parser",
     "../../core/fxcodec",
     "../../core/fxge",
diff --git a/testing/fuzzers/pdf_codec_fax_fuzzer.cc b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
index e27fc93..043860a 100644
--- a/testing/fuzzers/pdf_codec_fax_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_fax_fuzzer.cc
@@ -7,10 +7,7 @@
 
 #include "core/fxcodec/codec/ccodec_faxmodule.h"
 #include "core/fxcodec/codec/ccodec_scanlinedecoder.h"
-
-static int GetInteger(const uint8_t* data) {
-  return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
-}
+#include "testing/fuzzers/pdfium_fuzzer_util.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   static constexpr size_t kParameterSize = 21;
diff --git a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
index 8d59760..c218a27 100644
--- a/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_jbig2_fuzzer.cc
@@ -12,12 +12,9 @@
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/fx_dib.h"
+#include "testing/fuzzers/pdfium_fuzzer_util.h"
 #include "third_party/base/ptr_util.h"
 
-static uint32_t GetInteger(const uint8_t* data) {
-  return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;
-}
-
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   const size_t kParameterSize = 8;
   if (size < kParameterSize)
diff --git a/testing/fuzzers/pdfium_fuzzer_helper.h b/testing/fuzzers/pdfium_fuzzer_helper.h
index f9db00f..72ada4c 100644
--- a/testing/fuzzers/pdfium_fuzzer_helper.h
+++ b/testing/fuzzers/pdfium_fuzzer_helper.h
@@ -5,6 +5,8 @@
 #ifndef TESTING_FUZZERS_PDFIUM_FUZZER_HELPER_H_
 #define TESTING_FUZZERS_PDFIUM_FUZZER_HELPER_H_
 
+#include <stdint.h>
+
 #include "public/fpdfview.h"
 
 class PDFiumFuzzerHelper {
diff --git a/testing/fuzzers/pdfium_fuzzer_util.cc b/testing/fuzzers/pdfium_fuzzer_util.cc
new file mode 100644
index 0000000..9238f0e
--- /dev/null
+++ b/testing/fuzzers/pdfium_fuzzer_util.cc
@@ -0,0 +1,9 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/fuzzers/pdfium_fuzzer_util.h"
+
+int GetInteger(const uint8_t* data) {
+  return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+}
diff --git a/testing/fuzzers/pdfium_fuzzer_util.h b/testing/fuzzers/pdfium_fuzzer_util.h
new file mode 100644
index 0000000..d82f44b
--- /dev/null
+++ b/testing/fuzzers/pdfium_fuzzer_util.h
@@ -0,0 +1,13 @@
+// Copyright 2019 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_FUZZERS_PDFIUM_FUZZER_UTIL_H_
+#define TESTING_FUZZERS_PDFIUM_FUZZER_UTIL_H_
+
+#include <stdint.h>
+
+// Returns an integer from the first 4 bytes of |data|.
+int GetInteger(const uint8_t* data);
+
+#endif  // TESTING_FUZZERS_PDFIUM_FUZZER_UTIL_H_