Limit the size of 1D barcodes to 8K.

At 8K characters, 1D barcodes are likely > 50 inches in width. This is
likely sufficient for most use cases. Limit the size to stop the barcode
fuzzer from wasting time encoding larger barcodes.

BUG=chromium:939880

Change-Id: I3140e1be4df1715e3f3784bffa436d92b6d352ac
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/51851
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/cbc_codabar.cpp b/fxbarcode/cbc_codabar.cpp
index 5822cbe..0abfbf4 100644
--- a/fxbarcode/cbc_codabar.cpp
+++ b/fxbarcode/cbc_codabar.cpp
@@ -32,7 +32,7 @@
 CBC_Codabar::~CBC_Codabar() {}
 
 bool CBC_Codabar::Encode(WideStringView contents) {
-  if (contents.IsEmpty())
+  if (contents.IsEmpty() || contents.GetLength() > kMaxInputLengthBytes)
     return false;
 
   BCFORMAT format = BCFORMAT_CODABAR;
diff --git a/fxbarcode/cbc_code128.cpp b/fxbarcode/cbc_code128.cpp
index 712c1f7..a3da7bc 100644
--- a/fxbarcode/cbc_code128.cpp
+++ b/fxbarcode/cbc_code128.cpp
@@ -32,7 +32,7 @@
 CBC_Code128::~CBC_Code128() {}
 
 bool CBC_Code128::Encode(WideStringView contents) {
-  if (contents.IsEmpty())
+  if (contents.IsEmpty() || contents.GetLength() > kMaxInputLengthBytes)
     return false;
 
   BCFORMAT format = BCFORMAT_CODE_128;
diff --git a/fxbarcode/cbc_code39.cpp b/fxbarcode/cbc_code39.cpp
index 63a3c56..d9dc106 100644
--- a/fxbarcode/cbc_code39.cpp
+++ b/fxbarcode/cbc_code39.cpp
@@ -32,7 +32,7 @@
 CBC_Code39::~CBC_Code39() {}
 
 bool CBC_Code39::Encode(WideStringView contents) {
-  if (contents.IsEmpty())
+  if (contents.IsEmpty() || contents.GetLength() > kMaxInputLengthBytes)
     return false;
 
   BCFORMAT format = BCFORMAT_CODE_39;
diff --git a/fxbarcode/cbc_eancode.cpp b/fxbarcode/cbc_eancode.cpp
index ffb116e..9de16ae 100644
--- a/fxbarcode/cbc_eancode.cpp
+++ b/fxbarcode/cbc_eancode.cpp
@@ -20,7 +20,7 @@
 }
 
 bool CBC_EANCode::Encode(WideStringView contents) {
-  if (contents.IsEmpty())
+  if (contents.IsEmpty() || contents.GetLength() > kMaxInputLengthBytes)
     return false;
 
   BCFORMAT format = GetFormat();
diff --git a/fxbarcode/cbc_onecode.h b/fxbarcode/cbc_onecode.h
index 4470ad8..26aa943 100644
--- a/fxbarcode/cbc_onecode.h
+++ b/fxbarcode/cbc_onecode.h
@@ -18,6 +18,10 @@
 
 class CBC_OneCode : public CBC_CodeBase {
  public:
+  // Limit the size of 1D barcodes. Typical 1D barcodes are short so this should
+  // be sufficient for most use cases.
+  static constexpr size_t kMaxInputLengthBytes = 8192;
+
   explicit CBC_OneCode(std::unique_ptr<CBC_Writer> pWriter);
   ~CBC_OneCode() override;