]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: avoid aligning out of probing area
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 12 Jan 2024 07:47:50 +0000 (08:47 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 12 Jan 2024 07:57:19 +0000 (08:57 +0100)
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 <thomas@t-8ch.de>
libblkid/src/probe.c

index 64e794467a4623b0e23f9563954764d9b67e641a..76905e1970fbbd4270190c2515611a6714fdc5fe 100644 (file)
@@ -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;