Limit the input for PDF417 barcodes.

Like other barcode formats, PDF417 has limits on how big the input can
be.

BUG=chromium:960176

Change-Id: I7637bed30fe410e76356cac292ff5251f0ff7fdb
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55396
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/cbc_pdf417i.cpp b/fxbarcode/cbc_pdf417i.cpp
index c3e165b..f91f5c6 100644
--- a/fxbarcode/cbc_pdf417i.cpp
+++ b/fxbarcode/cbc_pdf417i.cpp
@@ -26,12 +26,23 @@
 #include "fxbarcode/pdf417/BC_PDF417Writer.h"
 #include "third_party/base/ptr_util.h"
 
+namespace {
+
+// Multiple source say PDF417 can encode about 1100 bytes, 1800 ASCII characters
+// or 2710 numerical digits.
+constexpr size_t kMaxPDF417InputLengthBytes = 2710;
+
+}  // namespace
+
 CBC_PDF417I::CBC_PDF417I()
     : CBC_CodeBase(pdfium::MakeUnique<CBC_PDF417Writer>()) {}
 
 CBC_PDF417I::~CBC_PDF417I() {}
 
 bool CBC_PDF417I::Encode(WideStringView contents) {
+  if (contents.GetLength() > kMaxPDF417InputLengthBytes)
+    return false;
+
   int32_t width;
   int32_t height;
   auto* pWriter = GetPDF417Writer();