From 6012cd1491600cd1577b51919c36bc35c0eb9ba6 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 26 Sep 2023 19:34:58 +0300 Subject: [PATCH] Improve EOF detection when reading command output Do not read a line from the command output and then check if we are at EOF, because it's possible that the writer immediately exited after writing the last line of output. Instead, switch the order of actions. This is a very serious bug that can lead to Dangerzone excluding the last page of the document. It should have bit us right from the start (see aeeed411a07699795aefae9f3feab84200c136bd), but it seems that the small period of time it takes the kernel to close the file descriptors was hiding this bug. Fixes #560 --- dangerzone/conversion/common.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dangerzone/conversion/common.py b/dangerzone/conversion/common.py index c8d062d..6db8dd7 100644 --- a/dangerzone/conversion/common.py +++ b/dangerzone/conversion/common.py @@ -63,10 +63,8 @@ class DangerzoneConverter: if they know its encoding. """ buf = b"" - while True: + while not sr.at_eof(): line = await sr.readline() - if sr.at_eof(): - break self.captured_output += line if callback is not None: callback(line)