Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

AF.3: keep Affinity out of CI's corpus and fuzz jobs; state the clean-room provenance

callmeBallochedb42922c124
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5baf73fb1..31b8d8566 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -206,8 +206,6 @@ jobs:
- { crate: codecs, name: decode_tiff }
- { crate: codecs, name: decode_exr }
- { crate: codecs, name: decode_heif }
- - { crate: affinity, name: preview }
- - { crate: affinity, name: import_preview, args: "--features io" }
- { crate: format, name: load }
steps:
- uses: actions/checkout@v4
@@ -219,7 +217,7 @@ jobs:
run: cargo install cargo-fuzz --locked
- name: Fuzz
working-directory: crates/${{ matrix.target.crate }}
- run: cargo fuzz run ${{ matrix.target.name }} ${{ matrix.target.args }} -- -max_total_time=${{ inputs.fuzz_seconds }}
+ run: cargo fuzz run ${{ matrix.target.name }} -- -max_total_time=${{ inputs.fuzz_seconds }}
- name: Upload crash artifacts
if: failure()
uses: actions/upload-artifact@v4
diff --git a/crates/affinity/README.md b/crates/affinity/README.md
index cfd39ec57..1929709e6 100644
--- a/crates/affinity/README.md
+++ b/crates/affinity/README.md
@@ -68,17 +68,41 @@ chunks contiguous, an optional PLTE unique and before IDAT, every chunk CRC must
end the file; compressed metadata (`zTXt`, `iTXt`, `iCCP`), APNG chunks and unknown critical chunks
are rejected. The I/O adapter decodes it with a 128 MiB allocation limit.
-## Provenance
-
-The container and object-stream layout was learned from [VMDevCpp/afread](https://github.com/VMDevCpp/afread)
-(MIT, at `04b672334a43e3e37ded6b5ffc57af231d589774`, written for container versions 7–11) and
-re-described in our own words before this Rust code was written; no code was translated. Its
-meaning was then worked out from public documents only, without running Affinity: the semantics of
-shapes, paints, text and pixel data were fitted to the thumbnail every Affinity document embeds
-(Affinity's own render of it) on 176 public documents saved by Affinity 1.x, 2.x and 3.0/3.1 on
-Windows, macOS and iPad. No GPL/AGPL code (such as Inkscape's Affinity extension) was read, and no
-Affinity application code, asset or document is part of this repository. The same reader is
-shared, as an independent copy, with VectorCraft's `vectorcraft-affinity`.
+## Provenance and clean-room
+
+Affinity has no published file-format specification, so this reader is built only from a public
+description of the format and from public files, never from Affinity itself. This is how
+PhotoCraft already treats formats that are only partly documented: `photocraft-psd` fills the gaps
+in Adobe's specification from the MIT-licensed psd-tools and ag-psd, and `photocraft-raw` recovered
+Nikon's compression tables by black-box analysis of CC0 sample files (see their READMEs).
+
+* **No Affinity software.** Affinity was never downloaded, installed, run, scripted, screenshotted or
+ disassembled for this work, and nothing from an Affinity installation (program code, resources,
+ presets, fonts, colour profiles) was read. No file was made with Affinity for it: every sample
+ is a document its author published.
+* **A public, permissively licensed description.** The container and object-stream layout was
+ learned from [VMDevCpp/afread](https://github.com/VMDevCpp/afread) (MIT, at
+ `04b672334a43e3e37ded6b5ffc57af231d589774`, written for container versions 7–11) and re-described
+ in our own words before this Rust code was written; no code was translated. No GPL/AGPL code (such
+ as Inkscape's Affinity extension) was read.
+* **Every structure checked against public files.** afread doesn't say how its author learned the
+ format, so nothing here rests on it alone: each structure the reader relies on is confirmed by
+ the public documents. Every archive entry carries a CRC-32 that must match, and every field in
+ the object stream names its own type, so a misread layout fails loudly instead of producing
+ plausible wrong data.
+* **Meaning fitted to Affinity's own pictures.** What shapes, paints, text and pixel data mean was
+ worked out by comparing our render with the thumbnail every Affinity document embeds (Affinity's
+ render of itself), on 176 public documents saved by Affinity 1.x, 2.x and 3.0/3.1 on Windows,
+ macOS and iPad. Most are published under CC0, MIT, BSD, Apache-2.0 or CC BY (-SA); the others
+ (no licence stated, or GPL or non-commercial terms) were only opened locally to compare
+ pictures, never committed or redistributed. The corpus test keeps the comparison for the pinned
+ files, which are CC0, MIT or Apache-2.0 only.
+* **Nothing of Affinity's is in this repository**: no program code, assets or documents. The test
+ files are fetched at pinned commits and sha256-verified, never committed.
+* **Read-only.** Nothing is written in Affinity's format; export waits until someone can check
+ written files in Affinity itself.
+
+The same reader is shared, as an independent copy, with VectorCraft's `vectorcraft-affinity`.
## Validation
@@ -90,9 +114,11 @@ shared, as an independent copy, with VectorCraft's `vectorcraft-affinity`.
(CC0), at pinned commits, each checked against `xtask/affinity-corpus.sha256`. `tests/real_files.rs`
parses them; `photocraft-io`'s `tests/affinity_corpus.rs` imports and flattens each one and
compares it with the thumbnail Affinity saved in it (mean difference 0–4.6 of 255, with a
- ceiling per file).
+ ceiling per file). This corpus is opt-in on its own: `corpus --all` and CI don't fetch it, so
+ run `cargo xtask corpus --affinity`, then
+ `cargo test -p photocraft-io --release --features corpus-affinity --test affinity_corpus`.
* `fuzz/` has `cargo-fuzz` targets for the whole reader (`preview`), the object stream (`stream`)
- and the I/O import (`import_preview`):
+ and the I/O import (`import_preview`), run locally (they aren't in CI's fuzz matrix):
```sh
cd crates/affinity/fuzz
diff --git a/crates/io/Cargo.toml b/crates/io/Cargo.toml
index 763297d10..66e4df6fb 100644
--- a/crates/io/Cargo.toml
+++ b/crates/io/Cargo.toml
@@ -12,6 +12,9 @@ workspace = true
[features]
# Real-file corpus tests (opt-in; `cargo xtask test-corpus`). Fail when the corpus is missing.
corpus = []
+# The Affinity corpus test (opt-in on its own: `cargo xtask corpus --affinity` fetches its files,
+# which `--all` and CI leave out until they move to photocraft-corpus).
+corpus-affinity = []
# HEIC/HEIF decode (forwarded to photocraft-codecs; see its `heif` feature).
heif = ["photocraft-codecs/heif"]
diff --git a/crates/io/tests/affinity_corpus.rs b/crates/io/tests/affinity_corpus.rs
index e4cb2921b..cb541ba4c 100644
--- a/crates/io/tests/affinity_corpus.rs
+++ b/crates/io/tests/affinity_corpus.rs
@@ -3,7 +3,9 @@
//! Affinity rendered when saving it. Each file's mean difference from that thumbnail (0–255 per
//! channel, both flattened on white, at the smaller of the two sizes) must stay under its ceiling,
//! set just above the difference measured when the importer landed.
-#![cfg(feature = "corpus")]
+//!
+//! Opt-in on its own (`--features corpus-affinity`): `corpus --all` and CI don't fetch these files.
+#![cfg(feature = "corpus-affinity")]
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use std::path::PathBuf;
diff --git a/docs/development.md b/docs/development.md
index 519d1c9d5..c448daf99 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -355,7 +355,7 @@ against committed **sha256 manifests**. All pins are in one place:
| `corpus/psd-tools/` | the complete psd-tools test set (309 files) | psd-tools upstream (MIT) | `xtask/psd-tools-corpus.sha256` |
| `corpus/heif/` | 9 small HEIC/HEIF files (checkerboards, RGB strips, a grid-tiled photo with EXIF/XMP, each with Apple's decode as `.ref.png`; a 10-bit RGBA file with its source PNG), for the `heif` feature | heic-rs (MIT OR Apache-2.0) and pillow-heif (BSD-3-Clause) upstreams | `xtask/heif-corpus.sha256` |
| `corpus/exr/` | the 5 deep OpenEXR test images (scanline deep data with half colour and u32 ID channels; 2.3 MB), checked against the ID manifests of their upstream sidecars | OpenEXR upstream at v3.5.2 (BSD-3-Clause) | `xtask/exr-corpus.sha256` |
-| `corpus/affinity/` | 21 public Affinity documents (four Affinity 3 `.af` files, `.afdesign` vector art, layer/shape/raster test files, a template with artboards), each holding Affinity's own render as its thumbnail | vector-art (CC0), AFDesignLoad, Jac21/Branding and AssetStoreTemplate (MIT) upstreams | `xtask/affinity-corpus.sha256` |
+| `corpus/affinity/` | 21 public Affinity documents (four Affinity 3 `.af` files, `.afdesign` vector art, layer/shape/raster test files, a template with artboards), each holding Affinity's own render as its thumbnail | vector-art (CC0), AFDesignLoad, Jac21/Branding and AssetStoreTemplate (MIT) upstreams. Opt-in: fetched only by `corpus --affinity` (not `--all`, not CI) and tested with `--features corpus-affinity` | `xtask/affinity-corpus.sha256` |
| `corpus/pngsuite/` | PngSuite | schaik.com release archive (public domain) | (fixed archive) |
```sh
diff --git a/xtask/src/corpus.rs b/xtask/src/corpus.rs
index 6bae7a395..ec0cfacd6 100644
--- a/xtask/src/corpus.rs
+++ b/xtask/src/corpus.rs
@@ -116,7 +116,7 @@ fn list() {
corpus/exr/ [{}] the deep OpenEXR test images (BSD-3-Clause), openexr@{}
manifest xtask/exr-corpus.sha256. Fetch: --exr
corpus/affinity/ [{}] 21 public Affinity 1–3 documents (CC0, MIT): vector-art, AFDesignLoad,
- Jac21/Branding, AssetStoreTemplate; manifest xtask/affinity-corpus.sha256. Fetch: --affinity
+ Jac21/Branding, AssetStoreTemplate; manifest xtask/affinity-corpus.sha256. Fetch: --affinity (not --all)
corpus/pngsuite/ [{}] PngSuite (public domain), {PNGSUITE_URL}. Fetch: --pngsuite
corpus/tiff/, corpus/raw/ optional, copied in by hand
diff --git a/xtask/src/corpus_pins.rs b/xtask/src/corpus_pins.rs
index 8e12c6919..393ff6183 100644
--- a/xtask/src/corpus_pins.rs
+++ b/xtask/src/corpus_pins.rs
@@ -225,5 +225,6 @@ pub const AFFINITY: PinnedCorpus = PinnedCorpus {
},
};
-/// Every pinned corpus, in fetch order.
-pub const ALL: &[&PinnedCorpus] = &[&PSD_MIXED, &PSD_TOOLS, &PHOTOSHOP, &HEIF, &EXR, &AFFINITY];
+/// Every pinned corpus `--all` fetches (and CI downloads), in fetch order. [`AFFINITY`] is
+/// fetched only on request (`--affinity`) until its files move to photocraft-corpus.
+pub const ALL: &[&PinnedCorpus] = &[&PSD_MIXED, &PSD_TOOLS, &PHOTOSHOP, &HEIF, &EXR];