code: def test_prevent_gs_invalid_xml(resources, outdir):
      generate_pdfa_ps(outdir / "pdfa.ps")
  
      # Inject a string with a trailing nul character into the DocumentInfo
      # dictionary of this PDF, as often occurs in practice.
      with pikepdf.open(resources / "trivial.pdf") as pdf:
          pdf.Root.DocumentInfo = pikepdf.Dictionary(
              Title=b"String with trailing nul\x00"
          )
          pdf.save(
              outdir / "layers.rendered.pdf", fix_metadata_version=False
          )
  
      _, options, _ = get_parser_options_plugins(
          args=[
              "-j",
              "1",
              "--output-type",
              "pdfa-2",
              "a.pdf",
              "b.pdf",
          ]
      )
      pdfinfo = PdfInfo(outdir / "layers.rendered.pdf")
      context = PdfContext(
          options,
          outdir,
          outdir / "layers.rendered.pdf",
          pdfinfo,
          get_plugin_manager([]),
      )
  
      convert_to_pdfa(
          str(outdir / "layers.rendered.pdf"),
          str(outdir / "pdfa.ps"),
          context,
      )
  
      contents = (outdir / "pdfa.pdf").read_bytes()
      # Since the XML may be invalid, we scan instead of actually feeding it
      # to a parser.
  
      xmp_start = contents.find(XMP_MAGIC)
      xmp_end = contents.rfind(b"<?xpacket end", xmp_start)
      assert 0 < xmp_start < xmp_end
      # Ensure we did not carry the nul forward.
      assert (
          contents.find(b"&#0;", xmp_start, xmp_end) == -1
      ), "found escaped nul"
      assert contents.find(b"\x00", xmp_start, xmp_end) == -1
  
imports: from __future__ import annotations
  import datetime
  import warnings
  from datetime import timezone
  from shutil import copyfile
  import pikepdf
  import pytest
  from packaging.version import Version
  from pikepdf.models.metadata import decode_pdf_date
  from ocrmypdf._exec import ghostscript
  from ocrmypdf._jobcontext import PdfContext
  from ocrmypdf._metadata import metadata_fixup
  from ocrmypdf._pipeline import convert_to_pdfa
  from ocrmypdf._plugin_manager import get_parser_options_plugins, get_plugin_manager
  from ocrmypdf.exceptions import ExitCode
  from ocrmypdf.pdfa import file_claims_pdfa, generate_pdfa_ps
  from ocrmypdf.pdfinfo import PdfInfo
  from .conftest import check_ocrmypdf, run_ocrmypdf, run_ocrmypdf_api
label_desc: Use image node_id 12 for calling a global function with example usage: test_prevent_gs_invalid_xml(resources, outdir) without return types