mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-31 05:46:46 -06:00
Merge main into #1608
This commit is contained in:
+2
-1
File diff suppressed because one or more lines are too long
+87
-13
@@ -64,6 +64,16 @@ const MAX_VERSION_INDEX: u64 = 16 * 1024 * 1024;
|
||||
const MAX_VERSION_BYTES: u64 = 1024 * 1024 * 1024;
|
||||
/// Most images, and image bytes together, read from one file (members past it are left out).
|
||||
const IMAGE_BUDGET: ImageBudget = ImageBudget { images: 20_000, bytes: 4 * 1024 * 1024 * 1024 };
|
||||
/// Most bytes one open of a `.figcraft` file unpacks, every area together: its document, images,
|
||||
/// published library, version history and branches ([`Unpacked`], #1079). Each area keeps its own
|
||||
/// cap; their sum was about 10 GB. Read in that order, the document (a 900 000-layer one unpacks
|
||||
/// to 1.5 GB) and the images up to their own 4 GiB cap fit, so a file whose images pass that cap
|
||||
/// (#1313: an 84 MiB document with 7.3 GiB of images) keeps as many as before; the history and
|
||||
/// branches share what is left. 32-bit targets (wasm32) have 4 GB of address space in all.
|
||||
#[cfg(not(target_pointer_width = "32"))]
|
||||
const MAX_UNPACKED: u64 = 6 * 1024 * 1024 * 1024;
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
const MAX_UNPACKED: u64 = 2 * 1024 * 1024 * 1024;
|
||||
const BRANCH_INDEX: &str = "branches/index.json";
|
||||
/// Most branches a file keeps: making more is refused, extra entries in a file are skipped.
|
||||
pub const MAX_BRANCHES: usize = 100;
|
||||
@@ -664,6 +674,42 @@ pub(crate) fn read_member<R: Read + Seek>(z: &mut zip::ZipArchive<R>, name: &str
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// What one file open may still unpack, every area together ([`MAX_UNPACKED`]).
|
||||
pub(crate) struct Unpacked {
|
||||
left: u64,
|
||||
total: u64,
|
||||
}
|
||||
|
||||
impl Unpacked {
|
||||
pub(crate) fn new(total: u64) -> Self {
|
||||
Self { left: total, total }
|
||||
}
|
||||
|
||||
/// Why a member is left out once the total is spent.
|
||||
fn passed(&self) -> String {
|
||||
match self.total / (1024 * 1024) {
|
||||
0 => format!("too large: the file's contents together pass {} bytes", self.total),
|
||||
mb => format!("too large: the file's contents together pass {mb} MB"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether member `name` (by its recorded size) needs more than is left.
|
||||
fn exceeded<R: Read + Seek>(&self, z: &mut zip::ZipArchive<R>, name: &str) -> bool {
|
||||
z.by_name(name).is_ok_and(|f| f.size() > self.left)
|
||||
}
|
||||
|
||||
/// [`read_member`] within `limit` (the area's own cap) and what is left of the total, which the
|
||||
/// member then uses up.
|
||||
pub(crate) fn read<R: Read + Seek>(&mut self, z: &mut zip::ZipArchive<R>, name: &str, limit: u64) -> Result<Vec<u8>, FormatError> {
|
||||
if self.exceeded(z, name) && z.by_name(name).is_ok_and(|f| f.size() <= limit) {
|
||||
return Err(FormatError::Corrupt(format!("{name}: {}", self.passed())));
|
||||
}
|
||||
let data = read_member(z, name, limit.min(self.left))?;
|
||||
self.left = self.left.saturating_sub(data.len() as u64);
|
||||
Ok(data)
|
||||
}
|
||||
}
|
||||
|
||||
/// Largest `document.json` read from an archive of `len` bytes in which it takes `packed`.
|
||||
pub(crate) fn document_limit(packed: u64, len: u64) -> u64 {
|
||||
packed.min(len).saturating_mul(DOCUMENT_RATIO).clamp(MAX_MEMBER, MAX_DOCUMENT)
|
||||
@@ -683,6 +729,11 @@ pub fn load_bytes_with_versions(bytes: &[u8]) -> Result<Loaded, FormatError> {
|
||||
|
||||
/// [`load_bytes_with_versions`] reading at most `budget` of images.
|
||||
pub(crate) fn load_within(bytes: &[u8], budget: ImageBudget) -> Result<Loaded, FormatError> {
|
||||
load_limited(bytes, budget, MAX_UNPACKED)
|
||||
}
|
||||
|
||||
/// [`load_within`] unpacking at most `total` bytes from the archive, every area together.
|
||||
pub(crate) fn load_limited(bytes: &[u8], budget: ImageBudget, total: u64) -> Result<Loaded, FormatError> {
|
||||
let trimmed = bytes.iter().position(|b| !b.is_ascii_whitespace()).and_then(|i| bytes.get(i));
|
||||
if trimmed == Some(&b'{') {
|
||||
let text = std::str::from_utf8(bytes).map_err(|e| FormatError::Corrupt(e.to_string()))?;
|
||||
@@ -692,18 +743,19 @@ pub(crate) fn load_within(bytes: &[u8], budget: ImageBudget) -> Result<Loaded, F
|
||||
let mut z = zip::ZipArchive::new(std::io::Cursor::new(bytes)).map_err(|e| FormatError::Corrupt(e.to_string()))?;
|
||||
let packed = z.by_name("document.json").map(|f| f.compressed_size()).unwrap_or(0);
|
||||
let limit = document_limit(packed, bytes.len() as u64);
|
||||
let text = String::from_utf8(read_member(&mut z, "document.json", limit)?).map_err(|e| FormatError::Corrupt(e.to_string()))?;
|
||||
let mut unpacked = Unpacked::new(total);
|
||||
let text = String::from_utf8(unpacked.read(&mut z, "document.json", limit)?).map_err(|e| FormatError::Corrupt(e.to_string()))?;
|
||||
let (mut doc, mut issues, own_images) = parse_json(&text)?;
|
||||
let ImagesRead { images, unread, past_budget } = read_images(&mut z, own_images.as_ref(), budget);
|
||||
let ImagesRead { images, unread, past_budget } = read_images(&mut z, own_images.as_ref(), budget, &mut unpacked);
|
||||
report_lost_images(&mut issues, &unread, &past_budget, own_images.as_ref(), &images);
|
||||
let images_past_budget = past_budget.len();
|
||||
match library::read(&mut z, &images, u64::MAX) {
|
||||
match library::read(&mut z, &images, &mut unpacked) {
|
||||
Ok(lib) => doc.published = lib.map(Arc::new),
|
||||
Err(e) => issues.push(format!("the published library was skipped: {e}")),
|
||||
}
|
||||
let mut budget = MAX_VERSION_BYTES;
|
||||
let versions = read_versions(&mut z, "versions", &images, &mut issues, &mut budget);
|
||||
let branches = read_branches(&mut z, &images, &mut issues);
|
||||
let versions = read_versions(&mut z, "versions", &images, &mut issues, &mut budget, &mut unpacked);
|
||||
let branches = read_branches(&mut z, &images, &mut issues, &mut unpacked);
|
||||
// Images only the version history or branches use stay with them.
|
||||
let branch_images =
|
||||
branches.iter().flat_map(|b| b.base.images.keys().chain(b.head.images.keys()).chain(b.versions.iter().flat_map(|v| v.images().keys())));
|
||||
@@ -720,7 +772,12 @@ pub(crate) fn load_within(bytes: &[u8], budget: ImageBudget) -> Result<Loaded, F
|
||||
/// The archive's `images/` members by hash, within `budget`, and the ones that couldn't be read
|
||||
/// with why. The document's own images (`own`) are read first, so a file past the budget loses
|
||||
/// the images only its history uses before its own.
|
||||
fn read_images<R: Read + Seek>(z: &mut zip::ZipArchive<R>, own: Option<&BTreeSet<String>>, budget: ImageBudget) -> ImagesRead {
|
||||
fn read_images<R: Read + Seek>(
|
||||
z: &mut zip::ZipArchive<R>,
|
||||
own: Option<&BTreeSet<String>>,
|
||||
budget: ImageBudget,
|
||||
unpacked: &mut Unpacked,
|
||||
) -> ImagesRead {
|
||||
let mut hashes: Vec<String> = z.file_names().filter_map(|n| n.strip_prefix("images/")).filter(|h| !h.is_empty()).map(str::to_string).collect();
|
||||
hashes.sort_by_key(|h| !own.is_some_and(|o| o.contains(h)));
|
||||
let mut images = BTreeMap::new();
|
||||
@@ -748,7 +805,14 @@ fn read_images<R: Read + Seek>(z: &mut zip::ZipArchive<R>, own: Option<&BTreeSet
|
||||
unread.push((hash, FormatError::Corrupt(format!("the file's images together pass {mb} MB"))));
|
||||
continue;
|
||||
}
|
||||
match read_member(z, &name, left.min(MAX_MEMBER)) {
|
||||
// Past the file's total, an image is left out as one past the images' own budget: it stays
|
||||
// in the file, which can't then be saved over without losing it (#1313).
|
||||
if unpacked.exceeded(z, &name) {
|
||||
past_budget.insert(hash.clone());
|
||||
unread.push((hash, FormatError::Corrupt(unpacked.passed())));
|
||||
continue;
|
||||
}
|
||||
match unpacked.read(z, &name, left.min(MAX_MEMBER)) {
|
||||
Ok(data) => {
|
||||
left = left.saturating_sub(data.len() as u64);
|
||||
images.insert(hash, image_data(data));
|
||||
@@ -812,12 +876,14 @@ fn read_versions<R: Read + Seek>(
|
||||
images: &BTreeMap<String, ImageData>,
|
||||
issues: &mut Vec<String>,
|
||||
budget: &mut u64,
|
||||
unpacked: &mut Unpacked,
|
||||
) -> Vec<Version> {
|
||||
let index_name = format!("{dir}/index.json");
|
||||
if z.index_for_name(&index_name).is_none() {
|
||||
return Vec::new();
|
||||
}
|
||||
let index = match read_member(z, &index_name, MAX_VERSION_INDEX)
|
||||
let index = match unpacked
|
||||
.read(z, &index_name, MAX_VERSION_INDEX)
|
||||
.and_then(|b| serde_json::from_slice::<Value>(&b).map_err(|e| FormatError::Corrupt(e.to_string())))
|
||||
{
|
||||
Ok(v) => v,
|
||||
@@ -838,7 +904,7 @@ fn read_versions<R: Read + Seek>(
|
||||
issues.push("a version with an invalid id was skipped".into());
|
||||
continue;
|
||||
}
|
||||
let json = match read_member(z, &format!("{dir}/{id}.json"), (*budget).min(MAX_MEMBER)) {
|
||||
let json = match unpacked.read(z, &format!("{dir}/{id}.json"), (*budget).min(MAX_MEMBER)) {
|
||||
Ok(j) => j,
|
||||
Err(err) => {
|
||||
issues.push(format!("version `{id}` was skipped: {err}"));
|
||||
@@ -869,11 +935,17 @@ fn read_versions<R: Read + Seek>(
|
||||
|
||||
/// The branches of an archive (none when it has no index), parsed. Damaged entries are skipped and
|
||||
/// reported in `issues`; nothing here fails the load.
|
||||
fn read_branches<R: Read + Seek>(z: &mut zip::ZipArchive<R>, images: &BTreeMap<String, ImageData>, issues: &mut Vec<String>) -> Vec<Branch> {
|
||||
fn read_branches<R: Read + Seek>(
|
||||
z: &mut zip::ZipArchive<R>,
|
||||
images: &BTreeMap<String, ImageData>,
|
||||
issues: &mut Vec<String>,
|
||||
unpacked: &mut Unpacked,
|
||||
) -> Vec<Branch> {
|
||||
if z.index_for_name(BRANCH_INDEX).is_none() {
|
||||
return Vec::new();
|
||||
}
|
||||
let index = match read_member(z, BRANCH_INDEX, MAX_VERSION_INDEX)
|
||||
let index = match unpacked
|
||||
.read(z, BRANCH_INDEX, MAX_VERSION_INDEX)
|
||||
.and_then(|b| serde_json::from_slice::<Value>(&b).map_err(|e| FormatError::Corrupt(e.to_string())))
|
||||
{
|
||||
Ok(v) => v,
|
||||
@@ -896,7 +968,7 @@ fn read_branches<R: Read + Seek>(z: &mut zip::ZipArchive<R>, images: &BTreeMap<S
|
||||
continue;
|
||||
}
|
||||
let mut snapshot = |part: &str, list: &str| -> Result<Arc<Document>, FormatError> {
|
||||
let json = read_member(z, &format!("branches/{id}/{part}.json"), budget.min(MAX_MEMBER))?;
|
||||
let json = unpacked.read(z, &format!("branches/{id}/{part}.json"), budget.min(MAX_MEMBER))?;
|
||||
budget = budget.saturating_sub(json.len() as u64);
|
||||
let (mut doc, _) = from_json(std::str::from_utf8(&json).map_err(|e| FormatError::Corrupt(e.to_string()))?)?;
|
||||
let hashes = e.get(list).and_then(Value::as_array).into_iter().flatten().filter_map(Value::as_str);
|
||||
@@ -916,7 +988,7 @@ fn read_branches<R: Read + Seek>(z: &mut zip::ZipArchive<R>, images: &BTreeMap<S
|
||||
time: e.get("time").and_then(Value::as_u64).unwrap_or(0),
|
||||
client: e.get("client").and_then(Value::as_u64).and_then(|c| u32::try_from(c).ok()).unwrap_or(0),
|
||||
state: e.get("state").and_then(|s| BranchState::deserialize(s).ok()).unwrap_or(BranchState::Active),
|
||||
versions: read_versions(z, &format!("branches/{id}/versions"), images, issues, &mut budget),
|
||||
versions: read_versions(z, &format!("branches/{id}/versions"), images, issues, &mut budget, unpacked),
|
||||
base,
|
||||
head,
|
||||
});
|
||||
@@ -996,6 +1068,8 @@ mod staging_tests;
|
||||
#[cfg(test)]
|
||||
mod thumbnail_tests;
|
||||
#[cfg(test)]
|
||||
mod unpacked_total_tests;
|
||||
#[cfg(test)]
|
||||
mod version_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::sync::Arc;
|
||||
|
||||
use figcraft_doc::{ImageData, LibraryManifest, NodeKind, PublishedLibrary, used_images};
|
||||
|
||||
use crate::{FormatError, MAX_MEMBER, from_json, image_data, io_err, json_options, put, put_json, read_member};
|
||||
use crate::{FormatError, MAX_MEMBER, Unpacked, from_json, image_data, io_err, json_options, put, put_json};
|
||||
|
||||
const MANIFEST: &str = "library/manifest.json";
|
||||
const SNAPSHOT: &str = "library/document.json";
|
||||
@@ -52,22 +52,22 @@ pub(crate) fn write<W: Write + Seek>(z: &mut zip::ZipWriter<W>, lib: &PublishedL
|
||||
}
|
||||
|
||||
/// The published library in an archive (`None` when the file was never published). `own` are
|
||||
/// the images already read from `images/`; `budget` caps the bytes its snapshot and images unpack
|
||||
/// to, together (beyond the per-part caps).
|
||||
/// the images already read from `images/`; what it unpacks comes out of `unpacked` (beyond the
|
||||
/// per-part caps).
|
||||
pub(crate) fn read<R: Read + Seek>(
|
||||
z: &mut zip::ZipArchive<R>,
|
||||
own: &BTreeMap<String, ImageData>,
|
||||
budget: u64,
|
||||
unpacked: &mut Unpacked,
|
||||
) -> Result<Option<PublishedLibrary>, FormatError> {
|
||||
if z.index_for_name(MANIFEST).is_none() {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut manifest: LibraryManifest = serde_json::from_slice(&read_member(z, MANIFEST, MAX_MANIFEST)?).map_err(corrupt)?;
|
||||
let mut manifest: LibraryManifest = serde_json::from_slice(&unpacked.read(z, MANIFEST, MAX_MANIFEST)?).map_err(corrupt)?;
|
||||
if !is_valid_library_id(&manifest.id) {
|
||||
return Err(corrupt("the library has an invalid id"));
|
||||
}
|
||||
let text = String::from_utf8(read_member(z, SNAPSHOT, budget.min(MAX_MEMBER))?).map_err(corrupt)?;
|
||||
let mut budget = budget.saturating_sub(text.len() as u64).min(MAX_IMAGE_BYTES);
|
||||
let text = String::from_utf8(unpacked.read(z, SNAPSHOT, MAX_MEMBER)?).map_err(corrupt)?;
|
||||
let mut budget = MAX_IMAGE_BYTES;
|
||||
let (mut doc, _) = from_json(&text)?;
|
||||
for hash in used_images(&doc) {
|
||||
if !ImageData::is_valid_key(&hash) {
|
||||
@@ -79,7 +79,7 @@ pub(crate) fn read<R: Read + Seek>(
|
||||
}
|
||||
let name = [format!("{IMAGES}{hash}"), format!("images/{hash}")].into_iter().find(|n| z.index_for_name(n).is_some());
|
||||
// A missing or oversized image shows as a placeholder, like in any other file.
|
||||
let Some(data) = name.and_then(|n| read_member(z, &n, budget.min(MAX_MEMBER)).ok()) else { continue };
|
||||
let Some(data) = name.and_then(|n| unpacked.read(z, &n, budget.min(MAX_MEMBER)).ok()) else { continue };
|
||||
budget = budget.saturating_sub(data.len() as u64);
|
||||
doc.images.insert(hash, image_data(data));
|
||||
}
|
||||
@@ -100,16 +100,15 @@ pub(crate) fn read<R: Read + Seek>(
|
||||
/// Read the published library of a `.figcraft` file (only its library entries are read): `None`
|
||||
/// when the file was never published, an error when it isn't a FigCraft archive or is damaged.
|
||||
pub fn read_library<R: Read + Seek>(r: R) -> Result<Option<PublishedLibrary>, FormatError> {
|
||||
let mut z = zip::ZipArchive::new(r).map_err(corrupt)?;
|
||||
read(&mut z, &BTreeMap::new(), u64::MAX)
|
||||
read_library_within(r, u64::MAX)
|
||||
}
|
||||
|
||||
/// [`read_library`] unpacking at most `max_bytes` in all (snapshot and images: an archive that
|
||||
/// would unpack to more is refused, or loses the images past it), for libraries from people the
|
||||
/// reader doesn't trust (a server).
|
||||
/// [`read_library`] unpacking at most `max_bytes` in all (manifest, snapshot and images: an
|
||||
/// archive that would unpack to more is refused, or loses the images past it), for libraries from
|
||||
/// people the reader doesn't trust (a server).
|
||||
pub fn read_library_within<R: Read + Seek>(r: R, max_bytes: u64) -> Result<Option<PublishedLibrary>, FormatError> {
|
||||
let mut z = zip::ZipArchive::new(r).map_err(corrupt)?;
|
||||
read(&mut z, &BTreeMap::new(), max_bytes)
|
||||
read(&mut z, &BTreeMap::new(), &mut Unpacked::new(max_bytes))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use super::*;
|
||||
use crate::{add_image, load_bytes, save_bytes};
|
||||
use crate::{add_image, load_bytes, read_member, save_bytes};
|
||||
use figcraft_doc::color::{ImageScaleMode, Paint};
|
||||
use figcraft_doc::{Document, LibraryAsset, NodeKind};
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//! One budget for everything a `.figcraft` file unpacks when it opens (#1079): the document,
|
||||
//! images, version history and branches share it, beyond each area's own cap, and what passes it
|
||||
//! is left out (or, for the document, refused) with a note that says so. Images left out this way
|
||||
//! stay in the file like those past the images' own budget (#1313).
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
use figcraft_doc::Document;
|
||||
use sha2::Digest;
|
||||
|
||||
use crate::{IMAGE_BUDGET, MAX_UNPACKED, load_limited, to_json};
|
||||
|
||||
fn png(k: u8) -> Vec<u8> {
|
||||
let img = image::RgbaImage::from_pixel(2, 2, image::Rgba([k, 7, 0, 255]));
|
||||
let mut out = Vec::new();
|
||||
img.write_to(&mut std::io::Cursor::new(&mut out), image::ImageFormat::Png).unwrap();
|
||||
out
|
||||
}
|
||||
|
||||
fn hash(bytes: &[u8]) -> String {
|
||||
format!("{:x}", sha2::Sha256::digest(bytes))
|
||||
}
|
||||
|
||||
fn zip_of(members: &[(String, Vec<u8>)]) -> Vec<u8> {
|
||||
let mut buf = std::io::Cursor::new(Vec::new());
|
||||
let mut z = zip::ZipWriter::new(&mut buf);
|
||||
for (name, bytes) in members {
|
||||
z.start_file(name.as_str(), zip::write::SimpleFileOptions::default()).unwrap();
|
||||
z.write_all(bytes).unwrap();
|
||||
}
|
||||
z.finish().unwrap();
|
||||
buf.into_inner()
|
||||
}
|
||||
|
||||
/// A crafted file: a document, two images, and a version history with one snapshot, each well
|
||||
/// within its own cap. The member sizes, in that order.
|
||||
fn crafted() -> (Vec<u8>, [u64; 5]) {
|
||||
let doc = serde_json::to_vec(&to_json(&Document::new("Crafted")).unwrap()).unwrap();
|
||||
let (a, b) = (png(1), png(2));
|
||||
let index = br#"{"versions": [{"id": "v1", "name": "First"}]}"#.to_vec();
|
||||
let snapshot = doc.clone();
|
||||
let sizes = [doc.len(), a.len(), b.len(), index.len(), snapshot.len()].map(|n| n as u64);
|
||||
let members = vec![
|
||||
("document.json".to_string(), doc),
|
||||
(format!("images/{}", hash(&a)), a),
|
||||
(format!("images/{}", hash(&b)), b),
|
||||
("versions/index.json".to_string(), index),
|
||||
("versions/v1.json".to_string(), snapshot),
|
||||
];
|
||||
(zip_of(&members), sizes)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn everything_within_the_total_loads() {
|
||||
let (bytes, sizes) = crafted();
|
||||
let loaded = load_limited(&bytes, IMAGE_BUDGET, sizes.iter().sum()).unwrap();
|
||||
assert_eq!(loaded.doc.images.len(), 2);
|
||||
assert_eq!(loaded.versions.len(), 1);
|
||||
assert!(loaded.issues.is_empty(), "{:?}", loaded.issues);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_passes_the_total_is_left_out_with_a_note() {
|
||||
let (bytes, [doc, a, b, index, _]) = crafted();
|
||||
// Room for the document and one image: the other image stays in the file, left out.
|
||||
let loaded = load_limited(&bytes, IMAGE_BUDGET, doc + a.max(b)).unwrap();
|
||||
assert_eq!(loaded.doc.images.len(), 1);
|
||||
assert_eq!(loaded.images_past_budget, 1, "kept in the file, so saving over it is refused");
|
||||
assert!(loaded.issues.iter().any(|i| i.contains("the file's contents together pass")), "{:?}", loaded.issues);
|
||||
// Room for the document, the images and the index, not the snapshot: the version is skipped.
|
||||
let loaded = load_limited(&bytes, IMAGE_BUDGET, doc + a + b + index).unwrap();
|
||||
assert_eq!(loaded.doc.images.len(), 2);
|
||||
assert!(loaded.versions.is_empty());
|
||||
let note = loaded.issues.iter().find(|i| i.contains("version `v1` was skipped")).unwrap();
|
||||
assert!(note.contains("the file's contents together pass"), "{note}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_document_past_the_total_is_refused_with_the_reason() {
|
||||
let (bytes, [doc, ..]) = crafted();
|
||||
let Err(e) = load_limited(&bytes, IMAGE_BUDGET, doc - 1) else { panic!("loaded") };
|
||||
assert!(e.to_string().contains("document.json: too large: the file's contents together pass"), "{e}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_total_leaves_room_for_the_largest_real_files() {
|
||||
// A 900 000-layer document unpacks to 1.5 GB; with images up to their own cap it fits, so a
|
||||
// file whose images pass that cap (#1313) loads as many as before.
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
const {
|
||||
assert!(MAX_UNPACKED >= 1_500_000_000 + IMAGE_BUDGET.bytes)
|
||||
};
|
||||
// Below what the per-area caps added up to (about 10 GB).
|
||||
const { assert!(MAX_UNPACKED < 10 * 1024 * 1024 * 1024) };
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# File format parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-30 · **Change:** minor (`.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumbent imports, with component set properties, and grid track sizes at its field ids; Save and auto-save don't replace changes another app made to the open file (#1330); `.sketch` import, best effort, Sketch 48 and newer; the PNG row names ignore overlapping layers and where include bounding box is offered; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-30 · **Change:** minor (opening a `.figcraft` file unpacks at most 6 GiB in all (2 GiB in the browser), every area together (#1079); `.fig` instance expansion no longer walks variable nodes for every instance or copies every outer override row into each nested instance (#1077); a FigJam `.jam` file opens as a board (#1342); FigJam `.jam` files open like `.fig` files: File ▸ Open, drag and drop, `file.import` and the command line (#1342); SVG import reads `color()` and `color-mix()` colours, with a note and a grey for those it can't (#1550); SVG import draws each pattern tile once per scale, within the layer budget (#1080); a file's JPEG thumbnail can't crash the home screen (#1491's progressive JPEG check, now shared); `.fig` import: library text styles linked by asset key, and override rows restating a nested level (#1234); `.fig` import keeps the file's saved line breaks while the text and its box are unedited (#1236); Download a missing free font from the Missing fonts window (`font.download`, #754); offline Penpot 2.x import/export (#1143); `.sketch` import checked against Sketch's renders: master backgrounds, symbol clipping, tints before Sketch 64, mask opacity, bitmap fills, image overrides on shapes, stretching stacks, blur radii, colour adjustments, OKLab gradients, text growth, shape group borders (#1389); FigJam outer shape outlines and sticky body fallback beside author text (#1341, #1397); image member names are checked on read, and REST image placeholders get archive-safe keys (#1086); Android Vector Drawable (XML) export; `.fig` export: files the incumbent imports, with component set properties, and grid track sizes at its field ids; Save and auto-save don't replace changes another app made to the open file (#1330); `.sketch` import, best effort, Sketch 48 and newer; the PNG row names ignore overlapping layers and where include bounding box is offered; the Fonts table's missing-font row describes the Missing fonts window; `.figcraft` carries the file kind (boards); `.fig` import: resized instances and variable modes by asset key; atomic saves; auto-save; SVG export clip of nested frames; SVG/PDF export depth refusal (#208); `.fig` export: instance sizes, variables with modes, shared styles, variable-width strokes; `.fig` export: written files checked by opening them in other software; experimental `.fig` export; export and inspect behaviour suite and fixes; .fig import: editable vector networks and more layer kinds; embedded image colour profiles; `.fig` import, best effort; animated GIF fills and TIFF images; last major: created, formats from the installed Figma's Info.plist and help center, ours from source; REST import keeps slot layers and instances' slot content (#792); REST import reads grid track sizes (#465); `.fig` import fidelity from the community batches, budgets for large files, the import report, a `.fig` copy from Save as, paste from another design app; instance layers' size and resizing and Hug on import (#731, #732)) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
Every format Figma reads or writes, with FigCraft's support. Sources: `Info.plist` of
|
||||
`/Applications/Figma.app` (document types only; nothing inside the bundle's code was read), Figma's
|
||||
@@ -185,6 +185,7 @@ source paint coordinates.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-30 | minor | M8, #1079: a `.figcraft` file unpacks at most 6 GiB in all when it opens (2 GiB in the browser), every area together, beyond each area's own cap; what passes it is left out with a note (images stay in the file, #1313). Numbers unchanged. |
|
||||
| 2026-10-30 | minor | M8, #1077: `.fig` import: instance expansion no longer walks variable nodes per instance or copies every outer override row into each nested instance; crafted files that took 14 s and 40 s import in 21 ms and 98 ms, normal files map as before. Numbers unchanged. |
|
||||
| 2026-10-30 | minor | M12, #1342: a FigJam `.jam` file opens as a board, our whiteboard file kind, instead of a design file: the `.fig` reader marks a canvas with FigJam's `fig-jam.` header as `FileKind::Board`, so the file opens with the board toolbar, the dot grid and the board panels, and saves as a board. A `.fig` stays a design file, and `file.import` of a `.jam` adds its pages to the open file without changing its kind. Its stickies and shapes with text are still frames with their generated layers and its connectors vectors, not native board objects. Tests: `board_import_tests.rs` (the kind, `.jam` against `.fig`), `jam_open_tests.rs` (open as a board, import into a design file). |
|
||||
| 2026-10-30 | minor | M6, #1342: FigJam `.jam` files open. A `.jam` is the same archive as a `.fig` (its canvas header reads `fig-jam.`), and the `.fig` reader already took it when a copy was renamed; now File ▸ Open, its file filter, drag and drop (home screen and canvas), `file.import` and the command line take `.jam` too, and the home screen's recent files show their thumbnails. What comes in is what the `.fig` reader makes of FigJam layers: stickies and shapes with text as frames with their generated layers, tables, stamps and the like as frames with an import note, connectors as vectors, and a layer type it doesn't know left out with a note naming it. The file opens as a design file, not a board, and its objects carry no board metadata yet. Tests: a synthetic `fig-jam.` canvas, bare and zipped (`board_import_tests.rs`), a `.jam` made from our own `.fig` export opened and imported (`jam_open_tests.rs`), the extension checks (`home_tests.rs`). |
|
||||
|
||||
+2
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user