Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-office/blob/main/README.md # omega-office Omega office documents: read and write office files in Omega Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-office / README.md` 455 lines · 36559 bytes Raw Blame History Rendered 1 # omega-office 2 3 I wrote omega-office so that the text of a word processing document and the cells of a spreadsheet can be 4 read by a tool whose every line anyone can inspect. It reads Office Open XML packages (ECMA-376, the same 5 text as ISO/IEC 29500): a `.docx` main document part as plain UTF-8 text, and one worksheet of an `.xlsx` 6 workbook as CSV. It is written in Omega (seeded Omegese) and built by the pinned seed-born compiler; 7 nothing else runs inside it. It is slice S2 of the no-black-box tools and stands on slice S1, omega-zip, 8 whose inflate and zip reader it carries in `vendor/omega-zip/`. 9 10 One program, `officeread`: 11 (named `ooffice` until 2026-11-10; renamed because `ooffice` is another office suite's launcher on some 12 Linux distributions) 13 14 | command | what it does | 15 |---|---| 16 | `officeread text FILE.docx` | the text of the main document part, one paragraph per line (UTF-8, LF) | 17 | `officeread csv FILE.xlsx [SHEET]` | one worksheet as CSV (RFC 4180, CR LF); SHEET is a sheet name, else a position 1, 2, ... when no sheet has that name; the first sheet by default | 18 | `officeread sheets FILE.xlsx` | the sheet names in workbook order, one per line | 19 | `officeread xmlev FILE [ENTRY]` | the XML event sequence of FILE, or of the zip entry ENTRY in FILE (the form the gate compares with expat) | 20 21 Every refusal is one line on stderr, `officeread: MESSAGE` (or `ozip: MESSAGE` from the zip engine), and a 22 documented exit code (table below). Standard output is buffered and written in 64 KiB pieces, the last at 23 the end, so only exit 0 means a complete result; after a refusal stdout may hold the pieces already 24 written (a 70000-byte text run before a mismatched end tag leaves 65536 bytes on stdout and exits 62). 25 26 ## What the proof proves, and what it does not 27 28 The gate below proves that the `officeread` built from exactly these sources by the pinned compiler gives the 29 oracles' output on the corpus (after the normalisation stated for each oracle, and with every difference 30 classified), refuses the malformed and out-of-bound inputs with the stated codes, kills the stated mutants, 31 and never traps or hangs on the cut and changed inputs of the sweep. It does not prove that `officeread` is 32 correct on every input, that it is fast, or that a file it reads is harmless: it reads what the package 33 says, within the bounds below. 34 35 ## Build 36 37 The compiler is omega-mv's seed-born `seed/out/omc` at the commit in `PIN` (sha256 in `PIN`). With an 38 omega-mv checkout at that commit (`sh seed/omega-from-seed.sh` rebuilds omc from the seed and must give 39 the same sha256): 40 41 ```sh 42 OMC=/path/to/omega-mv/seed/out/omc 43 cat src/head.om vendor/omega-zip/vendor/omega-mv/seed/text/text.om vendor/omega-zip/src/io.om \ 44 vendor/omega-zip/src/crc32.om vendor/omega-zip/src/inflate.om vendor/omega-zip/src/unzip.om \ 45 src/xml.om src/sink.om src/opc.om src/docx.om src/xlsx.om src/main.om | $OMC > officeread && chmod +x officeread 46 ``` 47 48 The units must be in that order (`src/head.om` carries the `om2` line; a text or const is visible only 49 after its line). The output is a static Linux AArch64 executable. `tests/gate.om` builds the same way (its 50 `UNITS` text) and is the receipt. 51 52 ## Gate 53 54 ```sh 55 mkdir -p build && $OMC < tests/gate.om > build/gate-bin && chmod +x build/gate-bin && build/gate-bin $OMC 56 ``` 57 58 Run from the repository root. The last line on success: 59 60 ``` 61 OFFICEREADGATE PASS cases=182 mutants-killed=30/30 robust-runs=46464 62 ``` 63 64 It exits 0 on PASS, 1 on any failure, 3 (NOT_RUN) when the compiler's SHA-256 is not the pin. It computes 65 that SHA-256 itself (FIPS 180-4). Then it: 66 67 1. builds `build/gate/officeread` from the units; 68 2. runs the cases of `tests/cases.txt`: exit status, stdout against the oracle (exactly, or after the 69 stated normalisation), and stderr (empty after success, exactly one `officeread:` or `ozip:` line after a 70 refusal); 71 3. builds each mutant of `tests/mutants.txt` (one or more source lines replaced) and requires a case to 72 fail on it; 73 4. robustness: every corpus input cut at 64 points and changed at 256 single bytes, 10 s limit each. 74 Every run must end with exit 0 or a documented refusal code, never a trap (101..114), a signal or the 75 time limit. For a zip package an exit 0 must print exactly what the unchanged package prints (a changed 76 byte inside compressed data is caught by the inflate checks or by the CRC-32, code 47). For a plain XML 77 file an exit 0 with different output is counted as `changed-plain`: plain XML has no checksum, so a 78 changed byte can simply be a changed character. 79 5. before step 2, builds `tests/docs.om` with the same compiler and runs it: publication checks of the 80 repository's own text (rules `tests/docrules.txt`: no local home paths, no source note citing a file 81 outside the repository or missing from it, no note leaving a question open, the licence present). It 82 prints `DOCS PASS ... mutants-killed=K/K` (its own mutants, `tests/docmutants.txt`); any other result 83 fails the gate. 84 85 Recorded 2026-11-10T07:18:51Z to 07:20:23Z on a clean `git archive` export of `e767cdab` (omega-zip `231dd336` 86 vendored unchanged, the command named `officeread`), in the pool-19 ticket (`taskset -c 19`, nice 10). The 87 earlier receipts (`ec493564`: 169 cases, 20 mutants; `c1a13734`: 170 cases, 21 mutants, printed with the old 88 prefix `OOFFICEGATE`) are in this file's history: 89 90 ``` 91 OFFICEREADGATE cases passed: expat=33 libreoffice-text=5 libreoffice-csv=9 exact=13; refusals passed: xml=65 package=41 zip=3 usage=4 92 OFFICEREADGATE mutants=23 killed=23 93 OFFICEREADGATE robustness files=137 runs=43584 refused=40220 exact=2191 changed-plain=737 accepted-after-change=436 failures=0 94 OFFICEREADGATE robustness exit codes: 10:72 11:91 12:63 13:1 14:256 15:364 16:344 17:134 18:226 19:1 21:791 40:4059 42:185 43:13 44:56 46:1515 47:489 48:14 50:731 53:1023 60:8522 61:3967 62:554 63:9096 64:301 65:586 66:683 67:612 68:56 70:83 71:38 72:111 73:206 74:21 75:110 80:616 81:1012 82:729 84:111 85:4 86:159 87:484 88:110 89:1621 95 OFFICEREADGATE PASS cases=173 mutants-killed=23/23 robust-runs=43584 96 ``` 97 98 Robustness: 137 files (22 packages and 17 XML files that are read, 41 package and 57 XML refusal fixtures) x 99 (64 cuts + 256 one-byte changes). No trap, signal or timeout; no package ever exited 0 with output other 100 than its unchanged output (2191 runs printed exactly that; 489 changed bytes were caught by the CRC-32, 47, 101 and the rest by the inflate, zip, XML and package checks). 737 runs on plain XML printed other events 102 (a changed character), and 436 runs turned a plain XML refusal fixture into a well-formed file. 103 104 Mutants (`tests/mutants.txt`; one or two lines replaced) and the case that killed each: 105 106 | mutant | change | killed by | 107 |---|---|---| 108 | m-entity | entity decoding off (`&` gives `?`) | x-basic | 109 | m-charref | character references off | x-basic | 110 | m-sstindex | shared string index off by one | c-cells | 111 | m-colref | column placement ignores the cell reference | c-cells | 112 | m-hardpath | relationship lookup replaced by the hard-coded path `word/document.xml` | t-alt | 113 | m-prefix | a prefixed element takes the default namespace | x-basic | 114 | m-doctype | DOCTYPE skipped instead of refused | rx-doctype-ext | 115 | m-movefrom | moved-from text printed | t-alt | 116 | m-quote | CSV quoting off | c-cells | 117 | m-attrspace | attribute-value normalisation off | x-text | 118 | m-crlf | line-end normalisation off | x-basic | 119 | m-utf8 | UTF-8 refusal off (the end-of-input check still refuses) | rx-utf8-then-mismatch | 120 | m-depth | nesting bound off | rb-depth1025 | 121 | m-phonetic | phonetic runs printed with shared strings | c-xalt | 122 | m-mediatype | media type of the main part not checked | rp-ctype | 123 | m-dotdot | `..` segments not removed | t-alt | 124 | m-cellsep | table cells separated by a space | t-features | 125 | m-boolean | TRUE printed as FALSE | c-xstrict | 126 | m-utf16le | UTF-16LE read as big-endian | x-utf16le | 127 | m-fastpath | the inline character-data path stores a wrong byte | z-plain | 128 | m-cdatafast | `]` and `>` take the inline character-data path, so `]]>` in a package part is not refused | rp-cdataend | 129 | m-attrfast | `<` and `&` take the inline attribute-value path, so they are not refused in a package part | z-squote (and rp-attramp) | 130 | m-attrquote | `'` takes the inline attribute-value path, so a value opened by `'` does not end at its `'` | z-squote | 131 | m-depthfast | the inline character-data path skips the depth check, so text after the root element of a package part is not refused | rp-textafter | 132 | m-namefast | the inline name path skips its first-character check, so `` in a package part is 62 (mismatched end tag), not 60 | rp-enddigit | 133 | m-ncname | an element's local part is not checked as an NCName | rx-ns-local-digit (and rx-ns-local-middot, rp-localdigit) | 134 | m-ncattr | an attribute's local part is not checked as an NCName | rx-ns-local-attr | 135 | m-ncdecl | the prefix of an `xmlns:p` declaration is not checked as an NCName | rx-ns-decl-digit | 136 | m-ncdec2 | the NameStartChar check after a colon decodes a two-byte character with the wrong lead-byte mask | x-ns-local2 | 137 | m-ncdec3 | the NameStartChar check after a colon reads one continuation byte of a three-byte character, not two | x-ns-local2 | 138 139 Without the fixtures rp-attramp, rp-attrlt and h-squote (the cases and corpus of `c6d510e3`), both new mutants 140 survive (2026-11-10T07:16Z): the inline paths of `src/sink.om` were only checked by plain-file refusals. 141 Negative controls, 2026-11-10T07:20:23Z to 07:21:51Z on the same export: the gate with another omc (omega-mv 142 `seed/out/omc` sha256 `0bca06df`...) prints `OFFICEREADGATE NOT_RUN: compiler sha256 is not the pin 143 `6d1b1cf5`...` and exits 3; with no argument it prints its usage and exits 3. A build whose stderr prefix is 144 `officereaX: ` (the first 9 bytes equal, which the gate's earlier fixed 9-byte compare let through) fails 145 111 cases on the stderr check. omega-zip `28e91f99`'s own `src/io.om` (its `fn wout`) next to `src/sink.om` 146 is refused by omc (error 10): the vendored files need no patch only because the seam is now omega-zip's. 147 The first negative control (06:15:04Z, `seed/rung4/om4.bin`) is in this file's history. 148 149 Proposed fix by factory inspection bay 3 (review of `06d4b937`, needs its own review): the gate on a clean 150 `git archive` export of `6307bdd2` (README.md is the only file that differs), 2026-11-10T08:17:06Z to 151 08:20:17Z, pool-0-2 (`taskset -c 0-2`, nice 19), exit 0, stderr empty: `cases passed: expat=34 152 libreoffice-text=5 libreoffice-csv=9 exact=13; refusals passed: xml=72 package=41 zip=3 usage=4`, 153 `mutants=28 killed=28`, `robustness files=145 runs=46144 ... failures=0`, last line 154 `OFFICEREADGATE PASS cases=181 mutants-killed=28/28 robust-runs=46144`. At `06d4b937` the mutants m-depthfast 155 and m-namefast survive (the inline paths of `src/sink.om` again checked only by plain-file refusals), and 156 `06d4b937`'s own build prints the text of rp-localdigit.docx with exit 0 and accepts every rx-ns-local and 157 rx-ns-decl fixture (exit 0) where expat refuses: the NCName check (Namespaces in XML 1.0 section 3) was 158 missing on both paths. 159 160 Proposed fix by factory inspection bay 8 (review of `fb793565`, needs its own review): the gate on a clean 161 `git archive` export of `10e81848` (README.md is the only file that differs), 2026-11-10T13:38:04Z to 162 13:41:17Z, pool-0-2 (`taskset -c 0-2`, nice 19), exit 0, stderr empty: `DOCS PASS files=20 paths-files=8 163 forbid=5 need=2 cases-file=1 mutants-killed=7/7`, `cases passed: expat=35 libreoffice-text=5 164 libreoffice-csv=9 exact=13; refusals passed: xml=72 package=41 zip=3 usage=4`, `mutants=30 killed=30`, 165 `robustness files=146 runs=46464 ... failures=0`, last line 166 `OFFICEREADGATE PASS cases=182 mutants-killed=30/30 robust-runs=46464`. At `fb793565` with only the two new 167 mutant lines added (2026-11-10T13:41:17Z to 13:44:28Z, same pool), m-ncdec2 and m-ncdec3 survive and the 168 gate exits 1 (`mutants=30 killed=28`): after a colon the corpus had only the lead bytes 0xC2, 0xC3, 0xE4, 169 0xE5 and 0xE6 (x-ns-local, x-names, rx-ns-local-middot), for which both mutated decodes give the same verdict. 170 171 `tests/mkcases.om` (Omega) regenerates every generated corpus file (`corpus/gen`) byte-identical. 172 173 ## Oracles 174 175 All oracles are test tools only, never part of omega-office; their outputs are committed with the commands 176 that made them (`corpus/SOURCES.txt`), so the gate itself needs only the pinned compiler. 177 178 | oracle | what it checks | cases | 179 |---|---|---| 180 | expat 2.6.1 through python3 3.12.3 `xml.sax` (xmllint is not installed on the Spark) | the XML event sequence (`xmlev`) of 18 plain files and of 17 parts inside the corpus packages (the second set goes through the inflate sink and its fast path) | 35 | 181 | LibreOffice 24.2.7.2 headless, `txt:Text (encoded):UTF8` | `text`: equal after the normalisation below | 5 | 182 | LibreOffice 24.2.7.2 headless, CSV filter with token 9 false (values as stored, not as shown) and token 12 = the sheet | `csv`: equal after the normalisation below | 9 | 183 | reviewed or hand-derived expected files | `text`, `csv`, `sheets` outputs whose LibreOffice difference is classified (`corpus/expect/*.lo.diff`), and the packages LibreOffice does not open, derived by hand from the clauses below | 13 | 184 185 I chose LibreOffice over python3 zipfile plus xml.sax for the spreadsheet oracle because it is an 186 independent implementation of the whole path (package, relationships, shared strings, cell placement), and 187 with "values as stored" it prints the stored cell values; a Python reader would have been my own reading of 188 the standard a second time. 189 190 Normalisation. Text: on both sides a leading UTF-8 byte order mark is removed (LibreOffice writes one), CR 191 LF becomes LF, and spaces and tabs at the end of each line are removed. CSV: my CR LF record ends (RFC 4180 192 2.1) are read as LF (LibreOffice writes LF); nothing else is changed on either side. 193 194 Every difference class found, with its files and the reason: 195 196 | class | LibreOffice prints | officeread prints | why | files | 197 |---|---|---|---|---| 198 | list and outline labels | the label of a numbered or bulleted paragraph (` • `, ` 1. `), and 7 spaces for a heading with an empty outline label | no label | labels come from the numbering part and its counters, which this slice does not read | features, lists | 199 | tracked deletions | deleted text (`removed words`) as if it were present | nothing for `del` (17.13.5.14) and `moveFrom` (17.13.5.22) | I print the text with every tracked change accepted: deleted and moved-away content is not part of it | features (and h-alt, which LibreOffice does not open) | 200 | footnote marks | the reference mark (`1`) | nothing | the mark is a counter of the footnotes part; footnotes are not read | features | 201 | recalculated fields | its own value of a page field (`0`) | the field result stored in the document (`1`) | I print the stored result (17.16.18, 17.16.19); there is no layout to recompute it | features | 202 | tables | every cell paragraph on its own line | one row per line, cells separated by a tab, paragraphs inside a cell separated by a space | the table form this slice defines | features, tables, h-strict | 203 | formatted numbers | a date, time or percentage cell in its number format (`2026-11-10`, `01:30:00 PM`, `12.5%`) although token 9 asks for stored values | the stored number (`46336`, `0.5625`, `0.125`) | formats are in the styles part, the next slice; a date is stored as a number | types sheet 1 | 204 | number text | its canonical number (`-0.0005`, `7`) | the stored text (`-0.5e-3`, `007`) | values print as stored | h-xalt sheet 1 | 205 | ISO 8601 date cells (`t="d"`) | a serial number (`46336`) | the stored text (`2026-11-10T00:00:00`) | values print as stored | h-xalt sheet 1 | 206 | a formula with no stored value | its computed value (`2`) | an empty field | there is no formula engine; only stored values are read | h-xalt sheet 1 | 207 208 LibreOffice 24.2.7.2 writes no output for `h-alt.docx` (the main part under another name, prefixed package 209 relationships, the prefix x) or `h-deflt.docx` (media type from a Default element, an absolute target, no 210 prefix); I did not find which feature stops it. Their expected text 211 is derived by hand from the clauses and checked against the rules above line by line. 212 213 The expat oracle and the XML refusals: expat refuses 51 of the 56 XML refusal fixtures too. The other five 214 are rules of this reader: a document type declaration (`rx-doctype`, `rx-doctype-ext`: ECMA-376 Part 2 215 6.2.5 b forbids DTDs in package XML), an encoding other than UTF-8 or UTF-16 (`rx-latin1`: Part 2 6.2.5 a), 216 UTF-16 without a byte order mark (`rx-utf16-nobom`: XML 1.0 4.3.3 requires it) and version 1.1 217 (`rx-version11`). Expat also accepts the six one-past-the-bound files. Its verdict 218 on each is in `corpus/refuse/ORACLE.txt`. 219 220 ## Exit codes 221 222 | code | meaning | cases | 223 |---|---|---| 224 | 0 | done | | 225 | 1 | usage: unknown command or wrong arguments | ru-* | 226 | 2 | cannot open the file | rz-no-file | 227 | 3, 4 | read error, write error | | 228 | 10..22, 30..32, 40..53 | the zip engine (omega-zip README "Exit codes"): input ends early, bad Huffman codes, distance too far back, output above the bound, not a zip file (40), ZIP64 (41), split archive (42), encrypted entry (43), method other than stored or deflated (44), local header disagrees (46), CRC-32 mismatch (47), entry above 1 GiB (48), malformed central directory (50), entries overlap, a possible zip bomb (51), size mismatch (52, 53) | rz-not-zip, rz-empty, robustness | 229 | 60 | not well-formed XML (XML 1.0 productions: tags, attributes, references, comments, CDATA, PIs, content outside the root, `]]>` in text) | rx-* | 230 | 61 | the XML ends before the document is complete (no root element, an open element or construct) | rx-truncated, rx-empty, rx-no-root, rx-comment-unclosed | 231 | 62 | an end tag does not match its start tag | rx-mismatch, rp-mismatch | 232 | 63 | bad UTF-8 (tx_u8st: overlong, surrogate, above U+10FFFF, stray or missing continuation), bad UTF-16 (lone surrogate, odd length), no byte order mark before UTF-16, a C0 control other than tab, LF and CR, or U+FFFE, U+FFFF (XML 1.0 2.2) | rx-utf8-*, rx-utf16-*, rx-control, rx-fffe | 233 | 64 | the XML declaration names an encoding other than that of the input, or a version other than 1.0 | rx-latin1, rx-utf16-declared, rx-version11 | 234 | 65 | a document type declaration: refused outright, so no entity beyond the five predefined ones exists and nothing is ever expanded or fetched (ECMA-376 Part 2 6.2.5 b) | rx-doctype, rx-doctype-ext, rp-doctype | 235 | 66 | an entity other than `amp lt gt quot apos`, or a character reference to a character XML 1.0 does not allow (0, surrogates, U+FFFE, U+FFFF, above U+10FFFF) | rx-entity, rx-cref*, rp-entity | 236 | 67 | namespace error (Namespaces in XML 1.0): an undeclared prefix, `xmlns:p=""`, the prefix `xmlns` declared or used on an element, `xml` bound elsewhere or another prefix bound to its URI, a name with two colons or a colon at either end, a prefix or local part that is not an NCName (`p:1x`) | rx-ns-*, rp-prefix, rp-localdigit | 237 | 68 | duplicate attribute, by name or by namespace URI and local name | rx-dup-* | 238 | 70 | a name longer than 256 bytes | rb-name257 | 239 | 71 | more than 256 attributes on one element | rb-attr257 | 240 | 72 | attribute names and values of one start tag above 262144 bytes | rb-abytes | 241 | 73 | elements nested deeper than 1024 | rb-depth1025 | 242 | 74 | more than 4095 namespace declarations in scope, or above 262144 bytes of their prefixes and URIs | rb-ns4096 | 243 | 75 | an entity or character reference longer than 32 bytes between `&` and `;` | rb-ref33 | 244 | 80 | not a package of the asked kind: no package relationships part, no relationship of type officeDocument, or the media type of the main part is not that of a word processing document (`text`) or a workbook (`csv`, `sheets`) | rp-norels, rp-notype, rp-ctype, rp-text-on-xlsx, rp-csv-on-docx, rp-sheets-on-docx | 245 | 81 | a part the package names is missing (the main part, the Media Types stream, a worksheet, the shared strings), or the sheet's relationship id is not in the workbook's Relationships part | rp-nomain, rp-noct, rq-*miss, rq-norel | 246 | 82 | a relationship target that is not a part name in this package: TargetMode External, a scheme, an empty or dot-ending segment, a directory, `?`, `#`, `\`, a percent-encoded `/` or `\`, above 4095 bytes | rp-external, rp-scheme, rp-trailing, rp-pctslash | 247 | 83 | no sheet with that name or position | rq-nosheet* | 248 | 84 | the chosen sheet's relationship is not of type worksheet (a chartsheet, dialogsheet, ...) | rq-chart* | 249 | 85 | shared strings above `1048576` items or `16777216` bytes, or one cell's text above `16777216` bytes | rq-sstmany | 250 | 86 | a shared string index that is not a decimal below the number of items | rq-sst* | 251 | 87 | a cell or row reference that is malformed (lowercase, no row), out of range (column above XFD = 16384, row 0 or above `1048576`), not ascending, or a cell reference whose row is not its row's | rq-ref*, rq-order, rq-roworder, rq-rowmis | 252 | 88 | a cell type other than those of ST_CellType, or a boolean that is not 0 or 1 | rq-type, rq-bool | 253 | 89 | a malformed package part: a wrong root element (Relationships, Types, workbook, sst, worksheet), a required attribute missing (Id, Type, Target; Extension, PartName, ContentType; sheet name and r:id), an unknown TargetMode, a media type or relationship id above 1024 bytes | rp-relsroot, rp-ctroot, rp-notarget, rp-badmode, rq-noid, rq-wbroot, rq-wsroot | 254 255 A trap (exit 101..114) would be a defect: the gate fails on one. 256 257 ## Bounds, and what happens at each 258 259 Nothing holds a whole part: the zip engine inflates a part 32 KiB at a time into the XML reader, which keeps 260 only the tag being read and the open elements. Globals: 64,116 bytes from omega-zip, then the reader 261 (1,095,268 bytes: a 256 KiB attribute pool, 256 KiB open-element names, 256 KiB namespace bytes, a 64 KiB text 262 buffer), the output and file buffers (131,112 bytes), the package (26,880 bytes), the shared string table (16 MiB pool and 8 MiB of offsets) and one cell value 263 (16 MiB): 43,265,936 bytes (41.26 MiB, computed by Wolfram from the declarations) in all; the compiler allows 1 GiB of globals and 16,777,216 elements per array 264 (OMEGESE.md, Size limits). Like omega-zip, this is a streaming tool and is not a profiled unit: its loop 265 bounds exceed the profile's 8192 and its globals the profile's 65,536 bytes (rule B3), by the lane's decision. 266 267 | bound | value | at the bound | 268 |---|---|---| 269 | element, attribute, end-tag or PI-target name | 256 bytes | refused, 70 | 270 | attributes on one element | 256 | refused, 71 | 271 | attribute names and values of one start tag | 262144 bytes | refused, 72 | 272 | element nesting | 1024 | refused, 73 | 273 | namespace declarations in scope | 4095 (4096 bindings with `xml`), 262144 bytes | refused, 74 | 274 | one entity or character reference | 32 bytes between `&` and `;` | refused, 75 | 275 | the XML declaration | 512 bytes | refused, 60 | 276 | character data | none: delivered in 64 KiB pieces | | 277 | part names, relationship targets | 4095 bytes (merged path 8191) | refused, 82 | 278 | media type, relationship id | 1024 bytes | refused, 89 | 279 | shared strings | 1,048,576 items, 16,777,216 bytes of text | refused, 85 | 280 | one cell value (inline string or v) | 16,777,216 bytes | refused, 85 | 281 | columns, rows | XFD (16384), `1048576` | refused, 87 | 282 | zip entry, entries, names | 1 GiB, 65535, 4095 bytes (omega-zip) | 48, 41 (ZIP64), 45 | 283 | plain XML file for `xmlev` | 64 TiB (1,000,000,000 reads of 64 KiB) | a trap would follow; not reachable in practice | 284 285 ## What it reads, and what it does not 286 287 `text` (ECMA-376 Part 1, WordprocessingML): 288 289 - Reads `document/body` (17.2.3, 17.2.2): the character data of every `t` (17.3.3.31) that is a child of a 290 run `r` (17.3.2.25), anywhere in the body: in paragraphs `p` (17.3.1.22), hyperlinks (17.16.22), 291 inserted runs `ins` (17.13.5.18), moved-to runs `moveTo` (17.13.5.25), content controls `sdt` 292 (17.5.2.29 to 17.5.2.36), smart tags and custom XML (17.5.1), simple fields (17.16.19), and the result 293 runs of complex fields (17.16.18). 294 - In a run: `tab` (17.3.3.32) and `ptab` (17.3.3.23) print a tab; `br` (17.3.3.1) of type textWrapping 295 or with no type and `cr` (17.3.3.4) print a line end, while page and column breaks print nothing; 296 `noBreakHyphen` (17.3.3.18) prints U+2011, `softHyphen` (17.3.3.29) prints U+00AD. 297 - A paragraph ends with LF; an empty paragraph is an empty line. 298 - Tables `tbl` (17.4.37): each row `tr` (17.4.78) is one line, the cells `tc` (17.4.65) separated by a 299 tab. Inside a table, the paragraphs of one cell, and tabs and breaks, are separated by a space. A nested 300 table's cells are joined into its outer cell with spaces. 301 - Markup compatibility (ECMA-376 Part 3): in `AlternateContent` the `Fallback` is read and every `Choice` 302 is skipped, since no Choice namespace is understood here. 303 - Not printed: deleted runs `del` (17.13.5.14) with their `delText` (17.3.3.7), moved-from runs `moveFrom` 304 (17.13.5.22); field codes `instrText` (17.16.23) and `delInstrText` (17.16.13); ruby text `rt` 305 (17.3.3.24), whose base text is printed; drawings, VML pictures and embedded objects (`drawing` 17.3.3.9, 306 `pict`, `object` 17.3.3.19) with any text box inside them; `sym` (17.3.3.30); all properties (`pPr`, 307 `rPr`, `sectPr`, `tblPr`, `tblPrEx`, `tblGrid`, `trPr`, `tcPr`, `sdtPr`, `sdtEndPr`); footnote and 308 endnote reference marks; list and heading labels. 309 - Not read at all: footnotes, endnotes, comments, headers and footers (separate parts), the numbering and 310 styles parts, the glossary document. 311 - Deleted text, decided: it is not printed. The standard says `del` content "shall be treated as deleted 312 content which has been tracked as a revision" (17.13.5.14), and moved-from content as "moved away from 313 this location" (17.13.5.22). I print the document as it reads with its revisions accepted. 314 315 `csv`, `sheets` (ECMA-376 Part 1, SpreadsheetML): 316 317 - The workbook (18.2.27): `sheets` (18.2.20) lists each `sheet` (18.2.19) with its `name` and `r:id`. The 318 worksheet and the Shared String Table are found through the workbook's Relationships part by relationship 319 type (worksheet, sharedStrings), never by a fixed name. 320 - Shared String Table (18.4.9): an item `si` (18.4.8) is the text of its `t` (18.4.12), directly or in rich 321 text runs `r` (18.4.4); phonetic runs `rPh` (18.4.6) are not part of the value. The whole table is held, 322 up to its bound (above, 85). 323 - Worksheet (18.3.1.99): `sheetData` (18.3.1.80), rows `row` (18.3.1.73), cells `c` (18.3.1.4). A cell is 324 placed by its reference `r`, and follows the previous cell when `r` is absent (rows likewise); rows and 325 cells must ascend (87). 326 - A cell's value is `v` (18.3.1.96), or `is` (18.3.1.53) for an inline string. Its type `t` (18.18.11 327 ST_CellType) is used as follows: `n` (the default) and `d` print the stored text; `s` prints that 328 shared string; `str` (a formula string) and `e` (an error such as `#DIV/0!`) print the stored text; 329 `inlineStr` prints the inline string; `b` prints `TRUE` or `FALSE`. Numbers are printed as written in 330 the file, never reformatted. 331 - Dates are stored as numbers (a serial day count) in cells with a date format, and I print that number. 332 Turning it into a date needs the number format in the styles part: the next slice. 333 - Strings are ST_Xstring (22.9.2.19): `_xHHHH_` is decoded on output (a surrogate pair of escapes is one 334 character; `_x005F_` is an underscore). 335 - The output is rows 1 to the last row that holds a value, each with fields 1 to the last column that 336 holds a value, so empty cells and rows are preserved and every record has the same number of fields. A 337 cell holds a value when it has `v` or `is`; a formula without a stored `v`, or a styled empty cell, holds 338 none. RFC 4180: a field with a comma, a quote, CR or LF is quoted with quotes doubled (2.6, 2.7), and 339 records end with CR LF (2.1). 340 - The sheet is read twice: once for the last row and column, once to print. 341 - Not read: styles and number formats, formulas (only their stored results), hidden state (hidden sheets 342 are listed and printed like any other), merged cells (the value is in the first cell), comments, tables, 343 pivot tables, charts, external links, the dimension element. 344 345 Package (ECMA-376 Part 2, Open Packaging Conventions, 5th edition): 346 347 - The package Relationships part `_rels/.rels` (6.5.2.2) names the main part (relationship type 348 officeDocument, Transitional or Strict URI). 349 - Its media type comes from the Media Types stream `[Content_Types].xml` (7.2.3, 7.3.7): an `Override` 350 for the part name, else a `Default` for its extension. It must be the main part of a word processing 351 document or template, or of a workbook or template (the media types of ECMA-376 Part 1). The part must 352 exist before its media type is checked. 353 - A part's own Relationships part is `_rels/NAME.rels` beside it (6.5.2.3). 354 - A target is resolved against its source part (6.4.2, RFC 3986 5.2): dot segments are removed, and a 355 leading `/` is relative to the package root. 356 - The result is mapped to a ZIP item name (7.3.4): the leading `/` removed, every non-ASCII byte 357 percent-encoded. 358 - Part names and extensions compare ASCII case-insensitively (6.2.2.3); relationship types compare exactly 359 (6.5.3.4); media types compare ASCII case-insensitively (RFC 7231 3.1.1.1). 360 - Transitional and Strict namespaces are both read. 361 - Not supported: macro-enabled and other vendor media types (`.docm`, `.xlsm`, `.xlsb` are refused with 362 80), percent-decoding of part names, interleaved parts (7.2.4), digital signatures (not checked), and a 363 main part named only by a non-ASCII Override part name. 364 365 XML (W3C XML 1.0 Fifth Edition, Namespaces in XML 1.0 Third Edition): 366 367 - Elements, attributes, character data, the five predefined entities, decimal and hexadecimal character 368 references, CDATA sections (their text), comments and processing instructions (skipped), one XML 369 declaration at the start (version 1.0; encoding, when named, that of the input; standalone yes or no). 370 - Input is UTF-8, with or without a byte order mark, or UTF-16 with a byte order mark (big- or 371 little-endian, surrogate pairs), turned into UTF-8. 372 - Line ends are normalised (2.11). In attribute values, a literal tab or line end becomes a space (3.3.3); 373 a character reference stays as written. 374 - Names are checked against the Fifth Edition NameStartChar and NameChar ranges (2.3). The non-ASCII names 375 in the corpus (U+00E9, U+4E2D, U+5B50, U+00B7, and after a colon U+0416, U+0905, U+30A2) are accepted by 376 both readers; I did not compare the two readers range by range. One difference is known: a name with a 377 character at or above U+10000 (`<` U+10000 `/>`, or the local part of `a:` U+10000) is accepted here, as 378 the Fifth Edition allows, and refused by expat 2.6.1 (invalid token); no gate case covers it, so the 379 four-byte branch of the check after a colon has no oracle case. 380 - Namespace prefixes resolve from the declarations in scope, and the handlers compare namespace URIs, never 381 prefixes. A prefix and a local part are each an NCName (Namespaces 1.0 sections 3 and 4): the character 382 after the colon must be a NameStartChar, so `p:1x`, `p:-x`, `p:.x`, `p:` U+00B7 `x` and `xmlns:1p` are 67. 383 - Not supported: DTDs (65), entities other than the five, encodings other than UTF-8 and UTF-16, XML 1.1, 384 colons in PI targets are not checked (Namespaces 1.0 section 7), and the `xml:space` and `xml:base` 385 attributes have no effect. 386 387 ## Measured speed 388 389 MEASURED 2026-11-10T06:16:45Z to about 06:19Z on the Spark (DGX Spark GB10, Linux AArch64), one core: 390 `taskset -c 10` inside the pool-10 ticket, nice 10, load average 18 to 22 on 20 cores. Times are from 391 `/usr/bin/time` (0.01 s resolution), using the binary the gate built (sha256 `0b3fea09`...`c83ad7d5`, 392 then named `ooffice`; not re-measured since), 3 runs 393 each with the same output bytes every time. Rates are by Wolfram from the median time. The inputs are made by 394 `build/mkcases DIR big` and packed with `zip -X -6`; they are not committed. 395 396 | command | input | median time (runs) | rate | 397 |---|---|---|---| 398 | `officeread text big.docx` | 600000 paragraphs: a 109,689,060-byte (104.61 MiB) main part, 1,841,266 bytes zipped | 8.19 s (8.17, 8.19, 8.23) | 12.77 MiB/s of WordprocessingML; 57,488,890 bytes of text out | 399 | `officeread csv big.xlsx` | 400000 rows of five cells: an 86,445,114-byte (82.44 MiB) sheet, read twice, and 1000 shared strings; 11,379,691 bytes zipped | 20.13 s (19.70, 20.13, 20.23) | 4.10 MiB/s of sheet (8.19 MiB/s of XML read over the two passes); 21,311,575 bytes of CSV out | 400 | `officeread xmlev big-document.xml` | the same main part as a plain file | 19.96 s (19.95, 19.96, 19.98) | 5.24 MiB/s in; 573,489,174 bytes of events out (27.40 MiB/s) | 401 402 Where the time goes. I measured this with stub builds on a 20,018,876-byte part, before the last speed-ups: 403 inflate alone took 0.40 s, and the XML reader the rest. Printable ASCII in text, names and attribute values is 404 stored inline; every other byte goes through a chain of calls, and every element through its namespace 405 resolution and handler. That per-element work sets the rate, which is why a sheet (many small elements) reads 406 slower than a document. The first build took 21.94 s on the same `text` input. A typical document part (under 407 1 MB) takes well under 0.1 s. 408 409 ## Standards followed 410 411 - ECMA-376 Part 1, 5th edition (December 2016): Fundamentals and Markup Language Reference, the clauses 412 named above (WordprocessingML 17, SpreadsheetML 18, ST_Xstring 22.9.2.19). 413 - ECMA-376 Part 2, 5th edition (December 2021): Open Packaging Conventions, 6.2.2, 6.2.5, 6.4, 6.5, 7.2.3, 414 7.3.4, 7.3.7. 415 - ECMA-376 Part 3: Markup Compatibility and Extensibility (AlternateContent, Choice, Fallback). 416 - W3C Extensible Markup Language (XML) 1.0, Fifth Edition: 2.2, 2.3, 2.4, 2.5, 2.6, 2.8, 2.11, 3.3.3, 4.1, 417 4.3.3, 4.6, appendix F. 418 - W3C Namespaces in XML 1.0, Third Edition: sections 3 to 6. 419 - RFC 4180 (CSV), RFC 3986 section 5.2 (resolving a relative reference), RFC 7231 3.1.1.1 (media types). 420 - The zip, inflate and CRC-32 standards of omega-zip: RFC 1951, the PKWARE APPNOTE 6.3.10, ISO 3309 / ITU-T V.42. 421 422 I read the standards' text (the Ecma downloads, on the Spark, not in this repository) and no other 423 program's source; the tools named above were only run as oracles on files of this corpus. 424 425 ## Reuse of omega-zip, and decisions recorded 426 427 - `vendor/omega-zip/` holds omega-zip at `231dd336`: `src/crc32.om`, `src/inflate.om`, `src/zlibd.om`, 428 `src/unzip.om`, `src/io.om` and its copy of omega-mv `seed/text/text.om`, all byte-identical (sha256 in 429 `vendor/omega-zip/PIN`), with no patch. 430 - The output seam is omega-zip's own: io.om's `wflush` runs `w = wout n` with the window `win[0 .. n)`, and 431 the program defines `fn wout n ulong to ulong`, returning n (ozip's `src/main.om` passes the window to 432 `woutfd`, the output descriptor). Omega has no imports and one namespace, so the program that includes 433 io.om supplies the one `wout`: here `src/sink.om`, the consumer of each inflated window. The call is an 434 assignment so that a build without `wout` is refused by omc (error 3); a bare `wout n` would compile as 435 the assignment `wout = n` and drop every byte. Before omega-zip `d0490914` the seam was a one-line rename 436 carried here as `vendor/omega-zip/sink.patch` (in this repository's history). 437 - `src/zlibd.om` is vendored with the others by the lane's decision; nothing in officeread calls it (not in the 438 build), and it is kept for the next slice (PDF streams are zlib). 439 - Memory: like omega-zip, officeread streams and is not a profiled unit; the profile's 65,536-byte total does 440 not apply to it (the lane's decision). Every bound is stated above with its refusal. 441 - The zip engine's own refusals keep its `ozip:` prefix and its codes; mine start at 60. 442 443 ## Files 444 445 - `src/`: the units (`head`, `xml`, `sink`, `opc`, `docx`, `xlsx`, `main`). 446 - `vendor/omega-zip/`: S1, pinned and unchanged (`PIN`). 447 - `tests/gate.om`, `tests/cases.txt`, `tests/mutants.txt`, `tests/mkcases.om`; `tests/docs.om` with 448 `tests/docrules.txt` and `tests/docmutants.txt` (publication checks, run by the gate). 449 - `corpus/`: sources, packages, refusal fixtures, oracle outputs; provenance and licences in 450 `corpus/SOURCES.txt`. 451 452 ## Licence 453 454 Apache-2.0 (`LICENSE`, `NOTICE`). `corpus/docx/letter.docx` is made from a LibreOffice template, MPL-2.0, 455 test data only (`corpus/SOURCES.txt`).