From: Thomas Weißschuh Date: Fri, 12 Jan 2024 07:47:50 +0000 (+0100) Subject: libblkid: avoid aligning out of probing area X-Git-Tag: v2.40-rc1~45^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=025b11465d086c55948eff484f40c993f2184990;p=thirdparty%2Futil-linux.git libblkid: avoid aligning out of probing area 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 --- diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 64e794467a..76905e1970 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -730,13 +730,18 @@ static int hide_buffer(blkid_probe pr, uint64_t off, uint64_t len) const 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;