From b0ae948a3352fc62a87e8d24b665cad1fb7be7bb Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 13 Sep 2024 09:04:08 -0700 Subject: [PATCH] Work around ruzstd only decoding a single frame of the zstd data. lld chunks the data into 1MB frames for parallel compression so almost everything will have multiple frames. --- src/symbolize/gimli/elf.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index f920a6fe..bf088f8d 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -357,11 +357,26 @@ fn decompress_zlib(input: &[u8], output: &mut [u8]) -> Option<()> { } } -fn decompress_zstd(input: &[u8], output: &mut [u8]) -> Option<()> { +fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> { use ruzstd::io::Read; - let mut decoder = ruzstd::StreamingDecoder::new(input).ok()?; - decoder.read_exact(output).ok() + while !input.is_empty() { + let mut decoder = ruzstd::StreamingDecoder::new(&mut input).ok()?; + loop { + let bytes_written = decoder.read(output).ok()?; + if bytes_written == 0 { + break; + } + output = &mut output[bytes_written..]; + } + } + + if !output.is_empty() { + // Lengths didn't match, something is wrong. + return None; + } + + Some(()) } const DEBUG_PATH: &[u8] = b"/usr/lib/debug";