---
title: "Can a sliced file crash the slicer that opens it?"
description: "A sliced file is somebody else's input. How Encrust's readers refuse a lying header: three guards, their limits in numbers, and nineteen fuzz targets."
url: "https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/"
lang: "en"
updated: "2026-11-17"
---

[ Resin printing, file formats and how a slicer works](https://encrust.app/blog/)

Inside the slicer

# A sliced file is somebody else's input

[By Vladimir Varvorkin](https://encrust.app/about/) Updated November 17, 2026 5 min read

Encrust's readers could, until the fuzzers found it: a header's layer count made one reserve memory for gigabytes of rows. Three guards now refuse such files with an error: a count checked against the file's size, a ceiling on the panel, and an archive entry grown under a cap.

## On this page

1. [A header is a claim](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#a-header-is-a-claim)
2. [The first guard: a count against the file](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#the-first-guard-a-count-against-the-file)
3. [The second guard: a panel against physics](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#the-second-guard-a-panel-against-physics)
4. [The third guard: an entry grown, not reserved](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#the-third-guard-an-entry-grown-not-reserved)
5. [The limits](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#the-limits)
6. [Nineteen fuzz targets](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#nineteen-fuzz-targets)
7. [What this shows](https://encrust.app/blog/can-a-3d-printing-file-crash-the-program-that-opens-it/#what-this-shows)

Two of Encrust’s readers, the `.ctb` and the `.pwmx` one, once reserved a layer table for gigabytes of rows because a header said so. Fuzzing found both ( [the fuzzing readme](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/fuzz/README.md)). The readers had believed their headers.

The surprise is how little it took. Our reader sized a table from the header’s layer count before checking it against the file.

This post covers Encrust’s readers only: the three checks that now stand between a header and an allocation, and the limits they use. [Opening a sliced file](https://encrust.app/guides/open-sliced-file-goo-ctb-pwmx/) shows the same readers from the screen.

## A header is a claim

Every number in a container header comes from whoever made the file: layer count, table address, panel size, run length, the uncompressed size of a zip entry. Our readers treat each as a claim. [The design note](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/docs/design/hostile-files.md) gives the reason in one line: sizing a buffer from one of them “has handed that person the allocator”.

The file might be corrupt rather than hostile. A download cut short or a damaged disk produces the same header lying about the bytes behind it. Our readers cannot tell which, and do not need to. [The security policy](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/SECURITY.md) promises a malformed file is refused, not crashed on, and that is the property the guards give.

## The first guard: a count against the file

`Reads::claim(what, count, each_bytes)` asks whether the file is large enough to hold the rows the header claims. `each_bytes` is the least one row can cost in the file: a layer table row is its fixed width. The answer is `count * each_bytes`, computed as a checked multiplication, compared with the file’s length. If it does not fit, the reader returns `ImpossibleCount` naming what was claimed and how many bytes were behind it. Only then does it reserve capacity.

The checked multiplication matters. A count near `u64::MAX` times a row width wraps around to a small number in plain arithmetic and passes. Here the overflow is itself the refusal. `Reads::bytes` applies the same test to a single length field before allocating ( [the code](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/crates/core-format/src/de.rs)).

The bound is loose on purpose. It compares against the whole file, not the bytes behind the table, because that is what one call knows without the caller seeking first. It only has to turn an unbounded allocation into one no larger than the file. The reads behind it fail on their own offsets anyway ( [design note](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/docs/design/hostile-files.md#the-three-guards)). A caller that passes a row cost smaller than the truth gets a weaker bound; that is the price of asking each caller to state it.

## The second guard: a panel against physics

No count in a file limits `width_px * height_px`: a mask is a mask, whatever compressed it. So `panel_in_range` multiplies the two with overflow checking and refuses anything above `MAX_PANEL_PX`, which is 256 x 1024 x 1024 = 268,435,456 pixels.

That is about three times the largest panel in our printer catalogue. Computed from the code’s own test: 15,120 x 6,230 = 94,197,600 pixels, and 268,435,456 / 94,197,600 is 2.85\. No printer we list is refused, and no header can ask for a mask the size of memory. A PNG’s own dimensions go through the same check, because in an archive container that is where the panel comes from ( [reader.rs](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/crates/core-format/src/reader.rs)).

The ceiling will date. A panel past 256 megapixels would be refused as hostile, and the day one ships the constant has to rise.

## The third guard: an entry grown, not reserved

A zip states each entry’s uncompressed size in its own directory. We do not allocate that much before decompressing one byte, because that would let the archive choose. `read_entry` instead reads through `take(MAX_ENTRY_BYTES + 1)` into a vector that grows with the bytes that arrive. If more than `MAX_ENTRY_BYTES` come out, it stops and returns an error naming the entry.

`MAX_ENTRY_BYTES` is `MAX_PANEL_PX` bytes: one 8-bit grey mask of the largest panel the first guard allows is the biggest thing an entry legitimately holds ( [de.rs](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/crates/core-format/src/de.rs)). The `.sl1`, `.cws` and gcode-zip readers go through it.

### The 3MF case

A 3MF is also a zip, but our mesh loader does not read it entry by entry the way our sliced-file readers do. A dependency parses the package, so we cannot wrap `read_entry` around it. Instead `refuse_oversized_parts` opens the archive first, reads every entry’s stated size from the directory without decompressing anything, and refuses the file if any part claims more than 2 GiB ( [three\_mf.rs](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/crates/core-mesh-io/src/three%5Fmf.rs)). Only then is the archive handed over.

The same file caps component nesting at 64 levels. The 3MF specification forbids a cycle, but nothing in a file stops one.

## The limits

| Limit             | Value             | What it bounds                                  | Where it comes from                                                                               |
| ----------------- | ----------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| MAX\_PANEL\_PX    | 268,435,456 px    | Panel pixels a header may claim                 | About 2.85 times the largest catalogue panel (94,197,600 px)                                      |
| MAX\_ENTRY\_BYTES | 268,435,456 bytes | One decompressed archive entry in a sliced file | One 8-bit mask of the largest permitted panel                                                     |
| MAX\_PART\_BYTES  | 2 GiB             | One part a 3MF directory may state              | A ceiling we chose; a model of a hundred million triangles is well under it, per the code comment |
| MAX\_DEPTH        | 64                | Nesting of 3MF components                       | A ceiling we chose                                                                                |

These are limits we set, not measurements of any machine. Only `MAX_PANEL_PX` has a physical anchor, and only against the printers in our catalogue.

## Nineteen fuzz targets

[The fuzzing readme](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/fuzz/README.md) lists nineteen targets: the mesh loaders; the Chitu, `.goo`, Anycubic, `.sl1`, gcode-zip, Creality, `.svgx` and `.cws` readers; the `.pws`, `.pwsz`, `.photons`, `.phz`, `.fdg`, encrypted `.ctb` and `.cxline` readers; a font loader; a resin-profile reader; and a sniffer that picks a reader for a file whose name says nothing.

The property they test is not that the file opens but that the reader answers: no panic, no hang, and no allocation proportional to a number in a header. Each reader is given the extension it expects, because a fuzzer spending its session failing a magic-number check tests only the magic-number check.

A crash found this way is kept. The reproducing input goes into the owning crate’s test fixtures and a test is added before the fix, so the fault cannot return unnoticed. The repository holds such files.

CI runs a short session per target on a schedule, not as a gate on a pull request. Two minutes of fuzzing is a smoke test, and failing a pull request over which inputs one random session reached would teach people to ignore it.

## What this shows

These are Encrust’s own readers, hardened by three guards and exercised by nineteen fuzz targets, so a damaged or hostile sliced file is refused with an error instead of crashing the program. A fuzzer finds faults; it does not prove their absence, and “no panic, no hang, no allocation proportional to a header number” is the property tested, not a guarantee about every input. [The security policy](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/SECURITY.md) says what to do if you find a file that breaks one.

## Sources

- [Encrust: reading a file somebody else wrote](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/docs/design/hostile-files.md)  · The three guards and what each bounds
- [Encrust: fuzzing the readers](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/fuzz/README.md)  · The nineteen targets, the corpus, and what happens to a crash
- [Encrust: security policy](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/SECURITY.md)  · What the project promises about a malformed file
- [Encrust: the guards in core-format](https://github.com/vvvlladimir/Encrust/blob/v0.9.0/crates/core-format/src/de.rs)  · Reads::claim, Reads::bytes, read\_entry and MAX\_ENTRY\_BYTES

## More in Inside the slicer

- [A resin slicer in a browser tab ](https://encrust.app/blog/resin-slicer-in-a-browser-webassembly/)
- [Which file does your resin printer read? ](https://encrust.app/blog/which-file-format-resin-printer/)
- [All posts ](https://encrust.app/blog/)

---

[ Encrust](https://encrust.app/)

Free and open source under AGPL-3.0, written in Rust. Your files stay on your computer.

## Product

[Download](https://encrust.app/download/) [Printers](https://encrust.app/printers/) [Web app](https://encrust.app/app/)

## Learn

[Guides](https://encrust.app/guides/) [Blog](https://encrust.app/blog/) [FAQ](https://encrust.app/faq/) [Changelog](https://github.com/vvvlladimir/Encrust/blob/main/CHANGELOG.md)

## Project

[About](https://encrust.app/about/) [Source code](https://github.com/vvvlladimir/Encrust) [Discussions](https://github.com/vvvlladimir/Encrust/discussions) [Report a bug](https://github.com/vvvlladimir/Encrust/issues)

Encrust prepares files for machines that cure resin with UV light. It can’t know whether your settings suit your resin, printer or model, so check its output before a long print. Provided without warranty, as the licence says.

[Privacy](https://encrust.app/privacy/) [Impressum](https://encrust.app/impressum/) [Datenschutzerklärung](https://encrust.app/datenschutz/)
