JFLib

diagram_io/src/vss/mod.rs#

Source: lib/diagram_io/src/vss/mod.rs

vss -- the binary formats of Visio 2003-2010 (.vss stencil; .vsd drawing and .vst template
alike) read into diagram_core's model, import only (DF-30; JD17).  Nothing is ever written in
these formats (NO-12).

  vss::read(&bytes, DocKind::Stencil, &vsdx::Limits::VSDX) -> Result<vsdx::Loaded, vsdx::Error>
                      one file; the caller says by its extension what it is (kind_of)
  vss::kind_of("vss") -> Some(DocKind::Stencil)     (vss vsd vst)
  vss::sniff(&bytes) -> bool         a compound file with a VisioDocument stream

Microsoft has published no specification of these formats.  This reader comes from our own
analysis of files (the container is the openly specified compound file, archive::cfb); no
code of other implementations is used.  What it found:
  container      a compound file with the stream VisioDocument (and the property sets
                 SummaryInformation and DocumentSummaryInformation)
  VisioDocument  a header and a tree of streams, some compressed (stream.rs)
  objects        chunk streams: a style, a sheet or a shape is a chunk at level 0, its sections
                 are lists (chunks with child IDs) at level 1, their rows chunks at level 2; a
                 row holds its cells as fixed fields (a number is a unit byte and a double), a
                 byte 1, a mask of the cells that hold a value of their own, then blocks: the
                 formulas (cells.rs, formula.rs)
  names          a list of strings; masters, styles and named rows point into it
The objects become the XML of Visio 2003-2010 (the format vdx.rs reads, whose element and cell
names Microsoft's schema reference documents), and vdx::read builds the model from that: so
both formats share every rule of the model, and what vdx.rs keeps or leaves out holds here too.

Every file is untrusted input, bounded like a VSDX file (vsdx::Limits): the compound file by
Limits::zip.archive_bytes, each stream after decompression by Limits::zip.part_bytes, all of
them by Limits::zip.total_bytes (LZSS cannot grow anything more than nine-fold), the tree of
streams by its depth and by each stream being used once, chunks by Limits::items, the XML made
from them by Limits::zip.part_bytes, and then everything vdx::read bounds.  Never a panic, no
recursion deeper than the format's fixed levels.
  • fn kind_of(ext: &str) -> Option<DocKind> the kind of document an extension of the binary formats stands for ("vss", "vsd", "vst"; ASCII case ignored)

  • fn sniff(bytes: &[u8]) -> bool whether bytes are a file of these formats: a compound file whose stream VisioDocument starts with Visio's signature (the directory is read, no stream but the start of that one)

  • fn read(bytes: &[u8], kind: DocKind, limits: &Limits) -> Result<Loaded, Error> read a binary file of Visio 2003-2010 (version 11) as a document of kind (see the module comment); limits bound everything (vsdx::Limits::VSDX for real files)

  • fn to_vdx(bytes: &[u8], kind: DocKind, limits: &Limits) -> Result<(String, Vec<Warning>), Error> the XML of Visio 2003-2010 (a .vdx, .vsx or .vtx by kind) that a binary file becomes before vdx::read builds the model from it, with the warnings of the conversion (what it left out); for checks and for opening the conversion in other programs

Source: docs/API.md in the JFLib repository.