mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Native format: refuse a .pcraft with out-of-range numbers when it is opened (#6862)
A number past f32's range (e.g. opacity 1e39) decoded as infinity, so the document opened but could never be saved again; read_manifest now refuses it as corrupt, naming the field. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
db46713c2c
commit
921637322c
2 files changed
+22
No files matched your search
@@ -163,6 +163,10 @@ pub(crate) fn read_manifest(src: &dyn ByteSource, opts: &LoadOptions) -> Result<
|
||||
let layers = take_array(&mut v, "/document/layers");
|
||||
let mut m: Manifest = serde_json::from_value(v)?;
|
||||
m.document.layers = layers_from_json(layers)?;
|
||||
// A number past f32's range decodes as infinity, which no save could write back (#6862).
|
||||
if let Err(crate::finite::Problem::NonFinite { path }) = crate::finite::check(&m) {
|
||||
return Err(FormatError::corrupt(format!("`{path}` is out of range")));
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,24 @@ fn bad_manifest_json() {
|
||||
assert!(matches!(load_from_bytes(&b), Err(FormatError::Json(_))));
|
||||
}
|
||||
|
||||
/// A number past f32's range would load as infinity, and every later save would then fail
|
||||
/// (#6862): it is refused when the file is opened, naming the value.
|
||||
#[test]
|
||||
fn out_of_range_number_refused_on_open() {
|
||||
let b = rebuild(&sample(), |n, d| {
|
||||
Some(if n == "manifest.json" {
|
||||
let mut v: serde_json::Value = serde_json::from_slice(&d).unwrap();
|
||||
v["document"]["layers"][0]["opacity"] = serde_json::json!(1e39);
|
||||
serde_json::to_vec(&v).unwrap()
|
||||
} else {
|
||||
d
|
||||
})
|
||||
});
|
||||
let Err(e) = load_from_bytes(&b) else { panic!("a manifest with opacity 1e39 opened") };
|
||||
assert!(matches!(e, FormatError::Corrupt(_)), "{e}");
|
||||
assert!(e.to_string().contains("document.layers[0].opacity"), "{e}");
|
||||
}
|
||||
|
||||
/// Hostile nesting fails with an error instead of overflowing the stack; nesting as deep as the
|
||||
/// deepest groups a bundle may hold (three JSON levels each) parses, and is then rejected for
|
||||
/// lacking a format version.
|
||||
|
||||
Reference in new issue
Block a user