From e504e9b89c514e9c829278b6f8a7dde7e4789e21 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 18 Jun 2022 14:21:56 +0800 Subject: [PATCH] attempt to limit memory size used by PNG decoder still getting a heap allocation failure, something is looking for 256k and even when the heap is increased to a couple megabytes we get heap allocation failures. --- Cargo.lock | 11 ----------- services/shellchat/src/cmds/net_cmd.rs | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9c855e48..9ed5b57d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,16 +1133,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fast_image_resize" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf174e621dc44fc6118d0e3289a1286c166ac28599e15651a82da23a14a3425" -dependencies = [ - "num-traits", - "thiserror", -] - [[package]] name = "fastrand" version = "1.7.0" @@ -2061,7 +2051,6 @@ name = "modals" version = "0.1.0" dependencies = [ "bit_field 0.9.0", - "fast_image_resize", "gam", "locales", "log", diff --git a/services/shellchat/src/cmds/net_cmd.rs b/services/shellchat/src/cmds/net_cmd.rs index 806568460..c9a3dbd4f 100644 --- a/services/shellchat/src/cmds/net_cmd.rs +++ b/services/shellchat/src/cmds/net_cmd.rs @@ -380,11 +380,14 @@ impl<'a> ShellCmdApi<'a> for NetCmd { let modals = modals::Modals::new(&env.xns).unwrap(); // have to add 4 to the start because the index is at the beginning of the header sequence, // not the end of the sequence. + log::info!("heap size: {}", heap_usage()); log::info!("decoding png starting with: {:x?}", &received[start+4..start+4+64]); - let decoder = png::Decoder::new(&received[start+4..]); + let decoder = png::Decoder::new_with_limits(&received[start+4..], png::Limits { bytes: 400 * 1024 }); + log::info!("heap size: {}", heap_usage()); let mut reader = decoder.read_info().expect("failed to read png info"); let mut buf = vec![0; reader.output_buffer_size()]; let info = reader.next_frame(&mut buf).expect("failed to decode png"); + log::info!("heap size: {}", heap_usage()); let (width, height) = (info.width, info.height); log::info!("image is {} x {}", width, height); @@ -701,3 +704,17 @@ impl Worker { } } } + +#[cfg(feature="ditherpunk")] +fn heap_usage() -> usize { + match xous::rsyscall(xous::SysCall::IncreaseHeap(0, xous::MemoryFlags::R)).expect("couldn't get heap size") { + xous::Result::MemoryRange(m) => { + let usage = m.len(); + usage + } + _ => { + log::error!("Couldn't measure heap usage"); + 0 + }, + } +} \ No newline at end of file