WeKnora icon indicating copy to clipboard operation
WeKnora copied to clipboard

[Bug]: docx 走 anydoc 后内嵌 EMF/WMF 图片的字节彻底不落盘(libreoffice 能转,但没接进 anydoc 路径)

Open JSJ189 opened this issue 1 month ago • 0 comments

Affected Component

anydoc parser path (WITH_ANYDOC=1) for .docx

Bug Description

When a .docx is parsed through the anydoc engine, embedded EMF/WMF pictures are not merely left un-rasterized — their bytes never reach object storage at all. They are silently dropped, with no log line, no resources row, and no images/image-N.bin recovery file.

This is worse than #4742 (markitdown path, where EMF/WMF bytes are preserved but the gallery fails to render them). With anydoc the data is gone before any later normalization step can rescue it.

Since docx/pptx now default to anydoc, every Word document containing Visio/EMF/WMF figures loses those figures permanently on (re)parse.

Environment

  • WeKnora v0.9.0, image built with --build-arg WITH_ANYDOC=1; docreader companion image same tag
  • GET /api/v1/system/parser-engines → anydoc: {"Available": true}
  • #3938 (the fix for #3932) is already in this build — the failure still reproduces
  • Image extraction + VLM enabled (image_processing_config.image_vector_enabled=true)

Reproduction

Document: a Word construction-method statement, 10.9 MB, containing Visio figures pasted into Word.

word/media/ inventory of the original file:

Extension Count
.png 60
.wmf 10
.emf 9
.jpeg 6
(no extension, 0 bytes) 1
total 86

After parse through anydoc: image_caption chunks = 62.

Matching each caption's image_info[].sha256 against the sha256 of every original word/media/* entry:

✅ 62/62 hit an original media entry, sha256 byte-identical
   matched originals: .png 57 + .jpeg 5
❌  0/19 of the EMF/WMF entries appear anywhere

So none of the 62 surviving images is a converted EMF — they are all byte-identical copies of the PNG/JPEG originals. The vector media simply vanished.

Missing entries (24 of 86):

.wmf  10   ← all
.emf   9   ← all   (largest: image51.emf 269,708 B; image19.emf 228,452 B)
.png   3
.jpeg  1
(none) 1   (0-byte placeholder)

resources table, filtered to assets written on the same day across the whole platform:

total 2330 | emf/wmf = 0 | png = 1570 | jpg = 591

2,330 image resources written, zero EMF/WMF rows. Not a single vector asset was ever persisted.

Expected Behavior

Any of these would be acceptable:

  1. Rasterize EMF/WMF (and OLE/Visio preview streams) to PNG before storage — this is the direction already taken by #4760 (LibreOffice fallback) and #4450. Note: those patches operate on already-persisted image resources. If the bytes are never persisted in the first place (this bug), they cannot fix the anydoc path.
  2. Route documents containing vector media away from anydoc to the docreader/markitdown path — the approach proposed for PPTX in #3933. The same routing needs to cover .docx; #3933's stated scope explicitly excludes it.
  3. At minimum, preserve the original bytes (as markitdown does today) so a later normalization pass can recover them, instead of dropping them.

Whatever is chosen, the loss must not be silent: reporting parse_status=completed while 19 embedded figures were discarded makes the failure invisible to operators.

Why an existing fix does not cover this

  • #3932 / #3938 — extension/markdown-link alignment for anydoc image refs. Fixed, present in this build, still reproduces (bytes never stored, so there is nothing for the resolver to resolve).
  • #3933 — pptx only. Comment on 2026-10-25 states the proposed patch is a bounded PPTX fix.
  • #4742 — reports docx EMF/WMF preserved as image/x-emf (markitdown behaviour). Different engine, different (less severe) symptom.
  • #4760 / #4450 — operate on resources that already exist in storage.

Additional context

The rasterization capability is not missing from the environment: inside the docreader container /usr/bin/soffice successfully converts these EMF files to PNG. ImageMagick (used by docreader/parser/pptx_media.py::_rasterize_with_imagemagick) fails with no decode delegate for this image format 'EMF', which is why the existing markitdown path yields all-black captions for these figures rather than usable images.

Also worth noting: docreader/parser/pptx_media.py is the only place in the codebase that knows about _VECTOR_EXT = {".wmf", ".emf", ".svg"}. There is no docx_media.py — Word documents have never had a rasterization path, in any engine.

Impact

On this deployment, 228 EMF/WMF figures across 7 knowledge bases are affected; one base alone has 78. All are construction drawings (system diagrams, layout plans, process flows) where the figure is the content — the accompanying text chunks cannot substitute for them.

JSJ189 avatar Nov 05 '26 02:11 JSJ189