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
+2
-8
@@ -23,7 +23,7 @@ use krilla::paint::{Fill, LineCap, Stroke};
|
||||
use krilla::pdf::{Pdf, PdfDocument, PdfError};
|
||||
use krilla::surface::Surface;
|
||||
use krilla::text::TextDirection;
|
||||
use krilla::{Data, Document, SerializeSettings};
|
||||
use krilla::{Document, SerializeSettings};
|
||||
|
||||
use super::{Item, PARTS};
|
||||
use crate::papers::{self, Paper, Pen, Values, width};
|
||||
@@ -159,13 +159,7 @@ fn shot(content_type: &str, kind: &str, bytes: Vec<u8>) -> Result<Shot, String>
|
||||
let dpi = density(content_type, &bytes)
|
||||
.filter(|d| *d >= 100.0)
|
||||
.unwrap_or(DEFAULT_DPI);
|
||||
let data: Data = bytes.into();
|
||||
let image = match content_type {
|
||||
"image/jpeg" => Image::from_jpeg(data, true),
|
||||
"image/png" => Image::from_png(data, true),
|
||||
"image/webp" => Image::from_webp(data, true),
|
||||
other => Err(format!("{other} is not an image type the app takes")),
|
||||
}?;
|
||||
let image = papers::picture(content_type, bytes)?;
|
||||
let (w, h) = image.size();
|
||||
Ok(Shot {
|
||||
fits: print_box(kind, w as f32, h as f32),
|
||||
|
||||
Reference in new issue
Block a user