Pictures: refuse a header that claims too many pixels, before decoding
The first fuzz run on cnx01 found it: a drawn signature of 798 bytes whose PNG header says 300 x 738,197,594 pixels made krilla ask for 885 GB. A failed allocation aborts the process, so one such signature on any client link (or such an upload in a pack) would have ended the app for everyone; reproduced on a normal build, with a valid IHDR checksum. krilla decodes a picture as soon as it makes it, so papers::pixels reads the size from the header first, with the decoder krilla uses (png, zune-jpeg, image-webp; already in Cargo.lock, now direct dependencies), and papers::picture refuses more than MAX_PIXELS (50 megapixels, about 200 MB decoded) before krilla sees the file. The pack and the Documents tab print a note for such a file, the signed copy refuses it, and the client page refuses the signature (422, "did not arrive whole") before anything is stored. tests/fuzz_cases/signed_copy/png-claims-885-gigabytes is the finding, replayed on every push; unit tests for the header sizes and the limit, and the agreements test sends the forged signature.
This commit is contained in:
1 parent
9b4d73c94b
commit
b7c9818dd6
9 files changed
+133
-12
No files matched your search
@@ -245,6 +245,31 @@ async fn the_client_signs_and_signs_again_after_a_change(pool: PgPool) {
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||
// a whole PNG whose header claims 300 x 738,197,594 pixels (found by the
|
||||
// nightly fuzzing): refused before it is decoded, and the app lives on
|
||||
let forged = {
|
||||
use base64::Engine;
|
||||
let png = include_bytes!("fuzz_cases/signed_copy/png-claims-885-gigabytes");
|
||||
format!(
|
||||
"data:image/png;base64,{}",
|
||||
base64::engine::general_purpose::STANDARD.encode(png)
|
||||
)
|
||||
};
|
||||
let r = client_post(
|
||||
&app,
|
||||
&uri,
|
||||
&csrf,
|
||||
&[
|
||||
("name", "Hans Becker"),
|
||||
("accept", "yes"),
|
||||
("version", &v1.to_string()),
|
||||
("drawing", &forged),
|
||||
],
|
||||
&[],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||
assert!(r.text().contains("did not arrive whole"));
|
||||
// without the link's token
|
||||
let r = client_post(
|
||||
&app,
|
||||
|
||||
Reference in new issue
Block a user