Commit ed190cd
authored
fix(gdpval): normalize python-docx ns0 namespacing before LibreOffice convert (#1270)
## Summary
Some `.docx` files in the GDPVal corpus are emitted by `python-docx` (or
similar `lxml`-based tools) and serialize the OPC package XML with an
explicit `ns0:` namespace prefix:
```xml
<ns0:Relationships xmlns:ns0="http://schemas.openxmlformats.org/...">
<ns0:Types xmlns:ns0="http://schemas.openxmlformats.org/...">
```
These are valid OOXML — Microsoft Word and pandoc accept them — but
LibreOffice 24.2 rejects them silently with `Error: source file could
not be loaded`. In the gdpval resources server this surfaces as `pdf
miss` events when preconverting task input documents.
The prefixing appears in BOTH `_rels/.rels` AND `[Content_Types].xml`.
Rewriting only one of them is not enough — both must be normalized for
LibreOffice to load the file.
`convert_to_pdf` now detects the `ns0:` prefix and, when present, writes
a namespace-normalized copy of the package to a tempdir and runs
LibreOffice on that copy. The original file on disk is left untouched
and the output PDF still lands next to the original.
## Empirical impact
Reproduced and verified on the actual vadams Kimi corpus on lustre.
Across the 46 source files in 27 affected GDPVal tasks:
| Failure mode | Files | Resolved by this PR |
|---|---|---|
| `ns0:` prefix in package XML | 43 | Yes |
| `ns0:` prefix + malformed `<Relationship>` chain | 2 | No (separate
cause) |
| Missing rels target parts (one `.pptx`) | 1 | No (out of scope) |
So this PR resolves 43/46 (~93%) of the failing source files. The
remaining 3 are outside the scope of this fix.
## Test plan
- [x] Unit tests for `_rewrite_ns0_namespace`, `_ooxml_has_ns0_prefix`,
`_normalize_ooxml_zip`, and `convert_to_pdf` selecting the normalized
copy when `ns0:` is present (21 tests pass)
- [x] End-to-end: pulled `Compensation Model Ideas.docx` from lustre (a
known-failing file), ran `convert_to_pdf` — produced a valid PDF with
the message "converted Compensation Model Ideas.docx (after ns0
normalization)"
- [x] Lint + format clean (`ruff check`, `ruff format --check`)
## Notes
- Out of scope: the 2 files with malformed `<Relationship>` chains in
`word/_rels/document.xml.rels` (caused by an upstream URL-redaction step
that left invalid XML) and the 1 `.pptx` with missing rels targets.
These need separate handling.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: Alex Gronskiy <agronskiy@nvidia.com>1 parent ace12f9 commit ed190cd
2 files changed
Lines changed: 276 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
15 | 38 | | |
16 | 39 | | |
17 | 40 | | |
18 | 41 | | |
19 | 42 | | |
20 | 43 | | |
21 | 44 | | |
| 45 | + | |
22 | 46 | | |
23 | 47 | | |
24 | 48 | | |
| 49 | + | |
25 | 50 | | |
26 | 51 | | |
27 | 52 | | |
| |||
32 | 57 | | |
33 | 58 | | |
34 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
35 | 96 | | |
36 | 97 | | |
37 | 98 | | |
| |||
41 | 102 | | |
42 | 103 | | |
43 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
44 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
45 | 115 | | |
46 | 116 | | |
47 | 117 | | |
| |||
55 | 125 | | |
56 | 126 | | |
57 | 127 | | |
58 | | - | |
| 128 | + | |
59 | 129 | | |
60 | 130 | | |
61 | 131 | | |
62 | 132 | | |
63 | 133 | | |
64 | 134 | | |
65 | 135 | | |
66 | | - | |
| 136 | + | |
| 137 | + | |
67 | 138 | | |
68 | 139 | | |
69 | 140 | | |
| |||
77 | 148 | | |
78 | 149 | | |
79 | 150 | | |
| 151 | + | |
| 152 | + | |
80 | 153 | | |
81 | 154 | | |
82 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
0 commit comments