Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1ec8ac8 authored by Colin Cross's avatar Colin Cross
Browse files

libsparse: fix 32 bit overflow when calculating last chunk

last_block * s->block_size can overflow when writing large filesystems,
cast to 64 bits before multiplying.

Change-Id: I3e54097852ce7d0fd271eab53d65e666284898e4
parent ec7d9dc7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ static int write_all_blocks(struct sparse_file *s, struct output_file *out)
				DIV_ROUND_UP(backed_block_len(bb), s->block_size);
	}

	pad = s->len - last_block * s->block_size;
	pad = s->len - (int64_t)last_block * s->block_size;
	assert(pad >= 0);
	if (pad > 0) {
		write_skip_chunk(out, pad);