Skip to content

Commit aae60e9

Browse files
Prevent OOM in ICO due to PNG
1 parent 2e121ab commit aae60e9

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

src/codecs/ico/decoder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ impl DirEntry {
249249
self.seek_to_start(&mut r)?;
250250

251251
if is_png {
252-
Ok(Png(Box::new(PngDecoder::new(r)?)))
252+
let limits = crate::Limits {
253+
max_image_width: Some(self.real_width().into()),
254+
max_image_height: Some(self.real_height().into()),
255+
max_alloc: Some(256 * 256 * 4 * 2), // width * height * 4 bytes per pixel * safety factor of 2
256+
};
257+
Ok(Png(Box::new(PngDecoder::with_limits(r, limits)?)))
253258
} else {
254259
Ok(Bmp(BmpDecoder::new_with_ico_format(r)?))
255260
}
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)