Skip to content

Commit 920fb05

Browse files
NoisyCoildavide125
authored andcommitted
Avoid dividing by zero when showing progress
PackageInstaller's fdcopy does not check if its `size` argument is zero before dividing `copied` by `size`. As a result, if non-image partitions in the installer package (typically, the ESP) contain empty files, copying those to disk raises a ZeroDivisionError that abruptly terminates the installation process, leaving it in an inconsistent state. Check if `size` is different than zero, and if it is skip showing progress (which is totally fine and desired). Signed-off-by: NoisyCoil <[email protected]>
1 parent ba7c798 commit 920fb05

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def fdcopy(self, sfd, dfd, size=None):
203203
st = time.time()
204204
self.ucache.bytes_read = 0
205205
while True:
206-
if size is not None:
206+
if size is not None and size != 0:
207207
prog = copied / size * 100
208208
sys.stdout.write(f"\033[3G{prog:6.2f}% ({ssize(bps)}/s)")
209209
sys.stdout.flush()

0 commit comments

Comments
 (0)