From 025b11465d086c55948eff484f40c993f2184990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 12 Jan 2024 08:47:50 +0100 Subject: [PATCH] libblkid: avoid aligning out of probing area MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When reading from the end of the device the IO size alignment could enlarge the read buffer outside of the probing area. This would then trigger a read failure. Signed-off-by: Thomas Weißschuh Reference:https://github.com/util-linux/util-linux/commit/025b11465d086c55948eff484f40c993f2184990 Conflict:Context adapt --- libblkid/src/probe.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index fee5b55..0e716b5 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -648,13 +648,18 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len) unsigned char *blkid_probe_get_buffer(blkid_probe pr, uint64_t off, uint64_t len) { struct blkid_bufinfo *bf = NULL; - uint64_t real_off, bias; + uint64_t real_off, bias, len_align; bias = off % pr->io_size; off -= bias; len += bias; - if (len % pr->io_size) - len += pr->io_size - (len % pr->io_size); + + if (len % pr->io_size) { + len_align = pr->io_size - (len % pr->io_size); + + if (pr->off + off + len + len_align <= pr->size) + len += len_align; + } real_off = pr->off + off; -- 2.33.0