xmlwf.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. <!--
  2. __ __ _
  3. ___\ \/ /_ __ __ _| |_
  4. / _ \\ /| '_ \ / _` | __|
  5. | __// \| |_) | (_| | |_
  6. \___/_/\_\ .__/ \__,_|\__|
  7. |_| XML parser
  8. Copyright (c) 2001 Scott Bronson <[email protected]>
  9. Copyright (c) 2002-2003 Fred L. Drake, Jr. <[email protected]>
  10. Copyright (c) 2009 Karl Waclawek <[email protected]>
  11. Copyright (c) 2016-2026 Sebastian Pipping <[email protected]>
  12. Copyright (c) 2016 Ardo van Rangelrooij <[email protected]>
  13. Copyright (c) 2017 Rhodri James <[email protected]>
  14. Copyright (c) 2020 Joe Orton <[email protected]>
  15. Copyright (c) 2021 Tim Bray <[email protected]>
  16. Unlike most of Expat,
  17. this file is copyrighted under the GNU Free Documentation License 1.1.
  18. -->
  19. <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  20. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  21. <!ENTITY dhfirstname "<firstname>Scott</firstname>">
  22. <!ENTITY dhsurname "<surname>Bronson</surname>">
  23. <!ENTITY dhdate "<date>March 17, 2026</date>">
  24. <!-- Please adjust this^^ date whenever cutting a new release. -->
  25. <!ENTITY dhsection "<manvolnum>1</manvolnum>">
  26. <!ENTITY dhemail "<email>[email protected]</email>">
  27. <!ENTITY dhusername "Scott Bronson">
  28. <!ENTITY dhucpackage "<refentrytitle>XMLWF</refentrytitle>">
  29. <!ENTITY dhpackage "xmlwf">
  30. <!ENTITY gnu "<acronym>GNU</acronym>">
  31. <!ENTITY debian "<productname>Debian &gnu;/Linux</productname>">
  32. ]>
  33. <refentry>
  34. <refentryinfo>
  35. <address>
  36. &dhemail;
  37. </address>
  38. <author>
  39. &dhfirstname;
  40. &dhsurname;
  41. </author>
  42. <copyright>
  43. <year>2001</year>
  44. <holder>&dhusername;</holder>
  45. </copyright>
  46. &dhdate;
  47. </refentryinfo>
  48. <refmeta>
  49. &dhucpackage;
  50. &dhsection;
  51. </refmeta>
  52. <refnamediv>
  53. <refname>&dhpackage;</refname>
  54. <refpurpose>Determines if an XML document is well-formed</refpurpose>
  55. </refnamediv>
  56. <refsynopsisdiv>
  57. <cmdsynopsis>
  58. <command>&dhpackage;</command>
  59. <arg><replaceable>OPTIONS</replaceable></arg>
  60. <arg><replaceable>FILE</replaceable> ...</arg>
  61. </cmdsynopsis>
  62. <cmdsynopsis>
  63. <command>&dhpackage;</command>
  64. <group choice="plain">
  65. <arg><option>-h</option></arg>
  66. <arg><option>--help</option></arg>
  67. </group>
  68. </cmdsynopsis>
  69. <cmdsynopsis>
  70. <command>&dhpackage;</command>
  71. <group choice="plain">
  72. <arg><option>-v</option></arg>
  73. <arg><option>--version</option></arg>
  74. </group>
  75. </cmdsynopsis>
  76. </refsynopsisdiv>
  77. <refsect1>
  78. <title>DESCRIPTION</title>
  79. <para>
  80. <command>&dhpackage;</command> uses the Expat library to
  81. determine if an XML document is well-formed. It is
  82. non-validating.
  83. </para>
  84. <para>
  85. If you do not specify any files on the command-line, and you
  86. have a recent version of <command>&dhpackage;</command>, the
  87. input file will be read from standard input.
  88. </para>
  89. </refsect1>
  90. <refsect1>
  91. <title>WELL-FORMED DOCUMENTS</title>
  92. <para>
  93. A well-formed document must adhere to the
  94. following rules:
  95. </para>
  96. <itemizedlist>
  97. <listitem>
  98. <para>
  99. The file begins with an XML declaration. For instance,
  100. <literal>&lt;?xml version="1.0" standalone="yes"?&gt;</literal>.
  101. <emphasis>NOTE</emphasis>:
  102. <command>&dhpackage;</command> does not currently
  103. check for a valid XML declaration.
  104. </para>
  105. </listitem>
  106. <listitem>
  107. <para>
  108. Every start tag is either empty (&lt;tag/&gt;)
  109. or has a corresponding end tag.
  110. </para>
  111. </listitem>
  112. <listitem>
  113. <para>
  114. There is exactly one root element. This element must contain
  115. all other elements in the document. Only comments, white
  116. space, and processing instructions may come after the close
  117. of the root element.
  118. </para>
  119. </listitem>
  120. <listitem>
  121. <para>
  122. All elements nest properly.
  123. </para>
  124. </listitem>
  125. <listitem>
  126. <para>
  127. All attribute values are enclosed in quotes (either single
  128. or double).
  129. </para>
  130. </listitem>
  131. </itemizedlist>
  132. <para>
  133. If the document has a DTD, and it strictly complies with that
  134. DTD, then the document is also considered <emphasis>valid</emphasis>.
  135. <command>&dhpackage;</command> is a non-validating parser --
  136. it does not check the DTD. However, it does support
  137. external entities (see the <option>-x</option> option).
  138. </para>
  139. </refsect1>
  140. <refsect1>
  141. <title>OPTIONS</title>
  142. <para>
  143. When an option includes an argument, you may specify the argument either
  144. separately ("<option>-d</option> <replaceable>output</replaceable>") or concatenated with the
  145. option ("<option>-d</option><replaceable>output</replaceable>"). <command>&dhpackage;</command>
  146. supports both.
  147. </para>
  148. <variablelist>
  149. <varlistentry>
  150. <term><option>-a</option> <replaceable>factor</replaceable></term>
  151. <listitem>
  152. <para>
  153. Sets the maximum tolerated amplification factor
  154. for protection against amplification attacks
  155. like the billion laughs attack
  156. (default: 100.0
  157. for the sum of direct and indirect output and also
  158. for allocations of dynamic memory).
  159. The amplification factor is calculated as ..
  160. </para>
  161. <literallayout>
  162. amplification := (direct + indirect) / direct
  163. </literallayout>
  164. <para>
  165. .. with regard to use of entities and ..
  166. </para>
  167. <literallayout>
  168. amplification := allocated / direct
  169. </literallayout>
  170. <para>
  171. .. with regard to dynamic memory while parsing.
  172. &lt;direct&gt; is the number of bytes read
  173. from the primary document in parsing,
  174. &lt;indirect&gt; is the number of bytes
  175. added by expanding entities and reading of external DTD files,
  176. combined, and
  177. &lt;allocated&gt; is the total number of bytes of dynamic memory
  178. allocated (and not freed) per hierarchy of parsers.
  179. </para>
  180. <para>
  181. <emphasis>NOTE</emphasis>:
  182. If you ever need to increase this value for non-attack payload,
  183. please file a bug report.
  184. </para>
  185. </listitem>
  186. </varlistentry>
  187. <varlistentry>
  188. <term><option>-b</option> <replaceable>bytes</replaceable></term>
  189. <listitem>
  190. <para>
  191. Sets the number of output bytes (including amplification)
  192. needed to activate protection against amplification attacks
  193. like billion laughs
  194. (default: 8 MiB for the sum of direct and indirect output,
  195. and 64 MiB for allocations of dynamic memory).
  196. This can be thought of as an &quot;activation threshold&quot;.
  197. </para>
  198. <para>
  199. <emphasis>NOTE</emphasis>:
  200. If you ever need to increase this value for non-attack payload,
  201. please file a bug report.
  202. </para>
  203. </listitem>
  204. </varlistentry>
  205. <varlistentry>
  206. <term><option>-c</option></term>
  207. <listitem>
  208. <para>
  209. If the input file is well-formed and <command>&dhpackage;</command>
  210. doesn't encounter any errors, the input file is simply copied to
  211. the output directory unchanged.
  212. This implies no namespaces (turns off <option>-n</option>) and
  213. requires <option>-d</option> to specify an output directory.
  214. </para>
  215. </listitem>
  216. </varlistentry>
  217. <varlistentry>
  218. <term><option>-d</option> <replaceable>output-dir</replaceable></term>
  219. <listitem>
  220. <para>
  221. Specifies a directory to contain transformed
  222. representations of the input files.
  223. By default, <option>-d</option> outputs a canonical representation
  224. (described below).
  225. You can select different output formats using <option>-c</option>,
  226. <option>-m</option> and <option>-N</option>.
  227. </para>
  228. <para>
  229. The output filenames will
  230. be exactly the same as the input filenames or "STDIN" if the input is
  231. coming from standard input. Therefore, you must be careful that the
  232. output file does not go into the same directory as the input
  233. file. Otherwise, <command>&dhpackage;</command> will delete the
  234. input file before it generates the output file (just like running
  235. <literal>cat &lt; file &gt; file</literal> in most shells).
  236. </para>
  237. <para>
  238. Two structurally equivalent XML documents have a byte-for-byte
  239. identical canonical XML representation.
  240. Note that ignorable white space is considered significant and
  241. is treated equivalently to data.
  242. More on canonical XML can be found at
  243. http://www.jclark.com/xml/canonxml.html .
  244. </para>
  245. </listitem>
  246. </varlistentry>
  247. <varlistentry>
  248. <term><option>-e</option> <replaceable>encoding</replaceable></term>
  249. <listitem>
  250. <para>
  251. Specifies the character encoding for the document, overriding
  252. any document encoding declaration. <command>&dhpackage;</command>
  253. supports four built-in encodings:
  254. <literal>US-ASCII</literal>,
  255. <literal>UTF-8</literal>,
  256. <literal>UTF-16</literal>, and
  257. <literal>ISO-8859-1</literal>.
  258. Also see the <option>-w</option> option.
  259. </para>
  260. </listitem>
  261. </varlistentry>
  262. <varlistentry>
  263. <term><option>-g</option> <replaceable>bytes</replaceable></term>
  264. <listitem>
  265. <para>
  266. Sets the buffer size to request per call pair to
  267. <function>XML_GetBuffer</function> and <function>read</function>
  268. (default: 8 KiB).
  269. </para>
  270. </listitem>
  271. </varlistentry>
  272. <varlistentry>
  273. <term><option>-h</option></term>
  274. <term><option>--help</option></term>
  275. <listitem>
  276. <para>
  277. Prints short usage information on command <command>&dhpackage;</command>,
  278. and then exits.
  279. Similar to this man page but more concise.
  280. </para>
  281. </listitem>
  282. </varlistentry>
  283. <varlistentry>
  284. <term><option>-k</option></term>
  285. <listitem>
  286. <para>
  287. When processing multiple files, <command>&dhpackage;</command>
  288. by default halts after the the first file with an error.
  289. This tells <command>&dhpackage;</command> to report the error
  290. but to keep processing.
  291. This can be useful, for example, when testing a filter that converts
  292. many files to XML and you want to quickly find out which conversions
  293. failed.
  294. </para>
  295. </listitem>
  296. </varlistentry>
  297. <varlistentry>
  298. <term><option>-m</option></term>
  299. <listitem>
  300. <para>
  301. Outputs some strange sort of XML file that completely
  302. describes the input file, including character positions.
  303. Requires <option>-d</option> to specify an output file.
  304. </para>
  305. </listitem>
  306. </varlistentry>
  307. <varlistentry>
  308. <term><option>-n</option></term>
  309. <listitem>
  310. <para>
  311. Turns on namespace processing. (describe namespaces)
  312. <option>-c</option> disables namespaces.
  313. </para>
  314. </listitem>
  315. </varlistentry>
  316. <varlistentry>
  317. <term><option>-N</option></term>
  318. <listitem>
  319. <para>
  320. Adds a doctype and notation declarations to canonical XML output.
  321. This matches the example output used by the formal XML test cases.
  322. Requires <option>-d</option> to specify an output file.
  323. </para>
  324. </listitem>
  325. </varlistentry>
  326. <varlistentry>
  327. <term><option>-p</option></term>
  328. <listitem>
  329. <para>
  330. Tells <command>&dhpackage;</command> to process external DTDs and parameter
  331. entities.
  332. </para>
  333. <para>
  334. Normally <command>&dhpackage;</command> never parses parameter
  335. entities. <option>-p</option> tells it to always parse them.
  336. <option>-p</option> implies <option>-x</option>.
  337. </para>
  338. </listitem>
  339. </varlistentry>
  340. <varlistentry>
  341. <term><option>-q</option></term>
  342. <listitem>
  343. <para>
  344. Disable reparse deferral, and allow quadratic parse runtime
  345. on large tokens (default: reparse deferral enabled).
  346. </para>
  347. </listitem>
  348. </varlistentry>
  349. <varlistentry>
  350. <term><option>-r</option></term>
  351. <listitem>
  352. <para>
  353. Normally <command>&dhpackage;</command> memory-maps the XML file
  354. before parsing; this can result in faster parsing on many
  355. platforms.
  356. <option>-r</option> turns off memory-mapping and uses normal file
  357. IO calls instead.
  358. Of course, memory-mapping is automatically turned off
  359. when reading from standard input.
  360. </para>
  361. <para>
  362. Use of memory-mapping can cause some platforms to report
  363. substantially higher memory usage for
  364. <command>&dhpackage;</command>, but this appears to be a matter of
  365. the operating system reporting memory in a strange way; there is
  366. not a leak in <command>&dhpackage;</command>.
  367. </para>
  368. </listitem>
  369. </varlistentry>
  370. <varlistentry>
  371. <term><option>-s</option></term>
  372. <listitem>
  373. <para>
  374. Prints an error if the document is not standalone.
  375. A document is standalone if it has no external subset and no
  376. references to parameter entities.
  377. </para>
  378. </listitem>
  379. </varlistentry>
  380. <varlistentry>
  381. <term><option>-t</option></term>
  382. <listitem>
  383. <para>
  384. Turns on timings. This tells Expat to parse the entire file,
  385. but not perform any processing.
  386. This gives a fairly accurate idea of the raw speed of Expat itself
  387. without client overhead.
  388. <option>-t</option> turns off most of the output options
  389. (<option>-d</option>, <option>-m</option>, <option>-c</option>, ...).
  390. </para>
  391. </listitem>
  392. </varlistentry>
  393. <varlistentry>
  394. <term><option>-v</option></term>
  395. <term><option>--version</option></term>
  396. <listitem>
  397. <para>
  398. Prints the version of the Expat library being used, including some
  399. information on the compile-time configuration of the library, and
  400. then exits.
  401. </para>
  402. </listitem>
  403. </varlistentry>
  404. <varlistentry>
  405. <term><option>-w</option></term>
  406. <listitem>
  407. <para>
  408. Enables support for Windows code pages.
  409. Normally, <command>&dhpackage;</command> will throw an error if it
  410. runs across an encoding that it is not equipped to handle itself. With
  411. <option>-w</option>, <command>&dhpackage;</command> will try to use a Windows code
  412. page. See also <option>-e</option>.
  413. </para>
  414. </listitem>
  415. </varlistentry>
  416. <varlistentry>
  417. <term><option>-x</option></term>
  418. <listitem>
  419. <para>
  420. Turns on parsing external entities.
  421. (CAREFUL! This makes xmlwf vulnerable to external entity attacks (XXE).)
  422. </para>
  423. <para>
  424. Non-validating parsers are not required to resolve external
  425. entities, or even expand entities at all.
  426. Expat always expands internal entities (?),
  427. but external entity parsing must be enabled explicitly.
  428. </para>
  429. <para>
  430. External entities are simply entities that obtain their
  431. data from outside the XML file currently being parsed.
  432. </para>
  433. <para>
  434. This is an example of an internal entity:
  435. <literallayout>
  436. &lt;!ENTITY vers '1.0.2'&gt;
  437. </literallayout>
  438. </para>
  439. <para>
  440. And here are some examples of external entities:
  441. <literallayout>
  442. &lt;!ENTITY header SYSTEM "header-&amp;vers;.xml"&gt; (parsed)
  443. &lt;!ENTITY logo SYSTEM "logo.png" PNG&gt; (unparsed)
  444. </literallayout>
  445. </para>
  446. </listitem>
  447. </varlistentry>
  448. <varlistentry>
  449. <term><option>--</option></term>
  450. <listitem>
  451. <para>
  452. (Two hyphens.)
  453. Terminates the list of options. This is only needed if a filename
  454. starts with a hyphen. For example:
  455. </para>
  456. <literallayout>
  457. &dhpackage; -- -myfile.xml
  458. </literallayout>
  459. <para>
  460. will run <command>&dhpackage;</command> on the file
  461. <filename>-myfile.xml</filename>.
  462. </para>
  463. </listitem>
  464. </varlistentry>
  465. </variablelist>
  466. <para>
  467. Older versions of <command>&dhpackage;</command> do not support
  468. reading from standard input.
  469. </para>
  470. </refsect1>
  471. <refsect1>
  472. <title>OUTPUT</title>
  473. <para><command>&dhpackage;</command> outputs nothing for files which are problem-free.
  474. If any input file is not well-formed, or if the output for any
  475. input file cannot be opened, <command>&dhpackage;</command> prints a single
  476. line describing the problem to standard output.
  477. </para>
  478. <para>
  479. If the <option>-k</option> option is not provided, <command>&dhpackage;</command>
  480. halts upon encountering a well-formedness or output-file error.
  481. If <option>-k</option> is provided, <command>&dhpackage;</command> continues
  482. processing the remaining input files, describing problems found with any of them.
  483. </para>
  484. </refsect1>
  485. <refsect1>
  486. <title>EXIT STATUS</title>
  487. <para>For options <option>-v</option>|<option>--version</option> or <option>-h</option>|<option>--help</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned:
  488. <variablelist>
  489. <varlistentry>
  490. <term><option>0</option></term>
  491. <listitem><para>The input files are well-formed and the output (if requested) was written successfully.</para>
  492. </listitem>
  493. </varlistentry>
  494. <varlistentry>
  495. <term><option>1</option></term>
  496. <listitem><para>An internal error occurred.</para>
  497. </listitem>
  498. </varlistentry>
  499. <varlistentry>
  500. <term><option>2</option></term>
  501. <listitem><para>One or more input files were not well-formed or could not be parsed.</para>
  502. </listitem>
  503. </varlistentry>
  504. <varlistentry>
  505. <term><option>3</option></term>
  506. <listitem><para>If using the <option>-d</option> option, an error occurred opening an output file.</para>
  507. </listitem>
  508. </varlistentry>
  509. <varlistentry>
  510. <term><option>4</option></term>
  511. <listitem><para>There was a command-line argument error in how <command>&dhpackage;</command> was invoked.</para>
  512. </listitem>
  513. </varlistentry>
  514. </variablelist>
  515. </para>
  516. </refsect1>
  517. <refsect1>
  518. <title>BUGS</title>
  519. <para>
  520. The errors should go to standard error, not standard output.
  521. </para>
  522. <para>
  523. There should be a way to get <option>-d</option> to send its
  524. output to standard output rather than forcing the user to send
  525. it to a file.
  526. </para>
  527. <para>
  528. I have no idea why anyone would want to use the
  529. <option>-d</option>, <option>-c</option>, and
  530. <option>-m</option> options. If someone could explain it to
  531. me, I'd like to add this information to this manpage.
  532. </para>
  533. </refsect1>
  534. <refsect1>
  535. <title>SEE ALSO</title>
  536. <para>
  537. <literallayout>
  538. The Expat home page: https://libexpat.github.io/
  539. The W3 XML 1.0 specification (fourth edition): https://www.w3.org/TR/2006/REC-xml-20060816/
  540. Billion laughs attack: https://en.wikipedia.org/wiki/Billion_laughs_attack
  541. </literallayout>
  542. </para>
  543. </refsect1>
  544. <refsect1>
  545. <title>AUTHOR</title>
  546. <para>
  547. This manual page was originally written by &dhusername; &dhemail;
  548. in December 2001 for
  549. the &debian; system (but may be used by others). Permission is
  550. granted to copy, distribute and/or modify this document under
  551. the terms of the &gnu; Free Documentation
  552. License, Version 1.1.
  553. </para>
  554. </refsect1>
  555. </refentry>