Skip to content

Crafted files: file values reach the IFC, glTF and SVG unsafely, host and cut chains set recursion depth, and four writer passes are quadratic #1845

Closed

Description

@DrunkOnJava

What

An audit of the IFC writer, the glTF, scene-graph and plan-SVG outputs, the viewer and Python bindings and the CLIs, at 1a9aacc7, found these. Each was confirmed by a second reader, and rvtDevelop re-read the ones marked (read). The bindings and CLIs had none. They are grouped by root cause, since each fix goes where the root is.

1. Values from the file reach the output unsafely

  • Comment injection (read). step_writer.rs emit_header writes /* {desc} */. desc holds the file's PartAtom id and BasicFileInfo version (ifc/mod.rs:1514-1528), escaped with escape. That makes a string literal safe, not a comment: a */ in the id ends the comment, and the rest is written as STEP between the header's ENDSEC; and DATA;.
  • Non-finite numbers in the IFC, glTF and SVG (read). The walker reads a stored float as a Float whatever it holds (walker.rs read_field_by_type). A NaN reaches IFCPOSITIVELENGTHMEASURE(NaN) through the stair property sets, inf reaches a glTF node matrix through as f32, and NaN reaches a plan path. Finite values of absurd size become infinite downstream: a record box's centre (partition_element_records.rs), and a stair's height from two elevations (native_stairs.rs). The String writers write a non-finite number as given, by their documented contract; write_step_to refuses the file.
  • A count sum overflows (read). revit_set_placement.rs:394 counts.iter().sum() over decoded stair counts (--revit-set-placement).

2. Recursion depth the file sets

  • Host chains in the scene graph (read). scene_graph.rs build_element_node recurses down host links, which a crafted file can chain door to door. The ring breaker walks every chain from every element with a linear seen.contains, O(n³). step_writer::storey_of already stops at 16.
  • Boolean-cut chains. One IfcBooleanResult per elevation-profile cut (wall_profile.rs cut_body), recursed by emit_solid_shape, solid_mesh and Drop. It is about 2,048 deep at most under SKETCH_MAX_CURVES; whether that overflows the viewer's stack needs a build to say.

3. Linear search where a map belongs (quadratic in elements)

  • step_writer.rs type_objects: groups.iter_mut().find(...) for every element (read).
  • ifc/mod.rs attach_hosted_cut_openings: every cut scans every entity for its host (read).
  • export_content.rs add_piece_sets: every element written in pieces rescans every entity's property sets.

4. Work with no cap before the allocation

  • export_content.rs contain_in_spaces: contents × spaces × ring vertices, with no cancellation check.
  • wall_tops.rs covered_pieces: the MAX_RISERS check comes after millions of rings are made; embedded subtracts every neighbour piece, tripling the pieces each time.
  • body_geometry.rs envelope_slab_mesh: pieces are capped, but not their points (about 8 GB at the cap).
  • mesh_volume.rs partner_ends: one grid cell holds every coincident mullion end, so n² comparisons.

Done when

  • Each is fixed where its root is: at decode, in the one function the outputs share, or by the structure that removes the blow-up. Not call site by call site.
  • Every export of a real file is byte for byte as before (an unfiltered Measure per PR), and a change the hashes do not see (the scene graph, the plan SVG) is said to be unmeasured.

Found by Tendrils audit workers (DeepSeek), checked by a second worker each.

Activity

  1. DrunkOnJava commented on Nov 13, 2026

    @DrunkOnJava
    OwnerAuthor

    The depth of a boolean-cut chain, measured (run 43420945188 and 43422082815, probe_1845_boolean_chain_depth, PR #1908), and the change that follows, with its rows registered before the run.

    #1846 to #1848 closed every item of this issue but one: a chain of boolean cuts is written and meshed by a loop now, but SolidShape is Debug, Clone and Serialize by derive and is dropped by the compiler's glue, and each walks the chain by recursion. The probe builds a chain by a loop and runs each operation on a thread of exactly 1 MiB (the viewer's wasm stack; a native thread stands in, so a failure here is not proof of one in the viewer), one child process per depth.

    operation holds at breaks at
    drop 16,384 65,536
    json (serde_json) 16,384 65,536
    clone 3,072 4,096
    debug 2,048 3,072

    My registered hypothesis (a 4,096-level chain survives all four) was wrong for clone and debug. A wall's chain has one level per cut region of its edited elevation profile, and a profile has at most SKETCH_MAX_CURVES (4,096) curves, so a region of one curve (a circle) makes a 4,096-level chain possible. Nothing in the export, the glTF, the scene graph or the viewer's bindings clones or prints a model (read: the one SolidShape clone is of the body before the cuts are made, from_decoded.rs:332), so the hazard is a library consumer's: a crafted file whose model is cloned or printed.

    The change (PR to follow): cut_profiles_from_bodies cuts a wall's regions in its body only up to MAX_BODY_CUTS (512, about 6 times under the depth at which debug breaks and 8 under clone's); a wall with more keeps its regions as its openings, which is what a wall whose regions are not all solids already does, so the openings Revit's export writes are written either way and only the body is not cut. Not a balanced union: a structure no real file produces would be a new IFC shape that nothing here validates.

    Rows, registered before its run (an unfiltered Measure against the merge-base):

    1. Every export and every diagnostics file of the unfiltered run is byte for byte as the base's: no wall of the corpus has more than 512 cut regions. If one has, the PR says which and the cap moves above it with the reason.
    2. The same-project gates check passes on the head.
    3. Not measured, and said so: a wall with more than 512 regions, which no file here has; the cap's effect on one is by reading.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions