xref: /aosp_15_r20/external/pdfium/testing/fuzzers/pdf_bidi_fuzzer.cc (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2018 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <cstdint>
6 #include <memory>
7 
8 #include "core/fxcrt/fx_codepage.h"
9 #include "core/fxcrt/widestring.h"
10 #include "core/fxge/cfx_font.h"
11 #include "core/fxge/fx_font.h"
12 #include "xfa/fgas/font/cfgas_gefont.h"
13 #include "xfa/fgas/layout/cfgas_char.h"
14 #include "xfa/fgas/layout/cfgas_rtfbreak.h"
15 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17   if (size > 8192)
18     return 0;
19 
20   auto font = std::make_unique<CFX_Font>();
21   font->LoadSubst("Arial", true, 0, FXFONT_FW_NORMAL, 0, FX_CodePage::kDefANSI,
22                   0);
23   assert(font);
24 
25   CFGAS_RTFBreak rtf_break(CFGAS_Break::LayoutStyle::kExpandTab);
26   rtf_break.SetLineBreakTolerance(1);
27   rtf_break.SetFont(CFGAS_GEFont::LoadFont(std::move(font)));
28   rtf_break.SetFontSize(12);
29 
30   WideString input =
31       WideString::FromUTF16LE(reinterpret_cast<const unsigned short*>(data),
32                               size / sizeof(unsigned short));
33   for (wchar_t ch : input)
34     rtf_break.AppendChar(ch);
35 
36   std::vector<CFGAS_Char> chars =
37       rtf_break.GetCurrentLineForTesting()->m_LineChars;
38   CFGAS_Char::BidiLine(&chars, chars.size());
39   return 0;
40 }
41