From 1db557d7afe62abc12f5cf1cf8a97bb541a725a9 Mon Sep 17 00:00:00 2001 From: Matteo Bertini Date: Mon, 29 May 2023 09:26:28 +0200 Subject: [PATCH] Avoid infinite loop writing and empty buffer In `write::BzDecoder::try_finish` do not loop if nothing was written Closes #96 --- src/write.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/write.rs b/src/write.rs index ddc16273..23cfd863 100644 --- a/src/write.rs +++ b/src/write.rs @@ -224,7 +224,8 @@ impl BzDecoder { /// Attempts to write data to this stream may result in a panic after this /// function is called. pub fn try_finish(&mut self) -> io::Result<()> { - while !self.done { + // If nothing was written, there is no need to loop + while !self.done && self.total_in() > 0 { self.write(&[])?; } self.dump()