]> www.infradead.org Git - mtd-utils.git/commitdiff
ubiformat: fix failure on big partitions (>4Gio)
authorRichard Genoud <richard.genoud@gmail.com>
Wed, 12 Sep 2012 14:37:19 +0000 (16:37 +0200)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 25 Sep 2012 14:04:09 +0000 (17:04 +0300)
The offset (which is 64bits when mtd-utils are not compile with
WITHOUT_LARGEFILE) is calculated like that:
offset = nb * size;
But nb and size are int, so on 32bits platforms, there's a possible
overflow.

So, it should be replace with:
offset = (off_t)nb * size;
If WITHOUT_LARGEFILE is defined, there still be an overflow, but it's
what we want, right ?

Cheney Chen tested an ubiformat on a NAND (5.9 GiB mtd part).

Reported-by: Cheney Chen <cheneychencl2012@gmail.com>
Tested-by: Cheney Chen <cheneychencl2012@gmail.com>
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
ubi-utils/libubigen.c

index 9eaa7f56c625afc22b5ed35fcfa4d42e7b0c1219..d2a949be90c2505f2d09a1ffd5c738e2d31c0224 100644 (file)
@@ -279,7 +279,7 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
        memset(outbuf + ui->data_offs + ui->vtbl_size, 0xFF,
               ui->peb_size - ui->data_offs - ui->vtbl_size);
 
-       seek = peb1 * ui->peb_size;
+       seek = (off_t) peb1 * ui->peb_size;
        if (lseek(fd, seek, SEEK_SET) != seek) {
                sys_errmsg("cannot seek output file");
                goto out_free;
@@ -293,7 +293,7 @@ int ubigen_write_layout_vol(const struct ubigen_info *ui, int peb1, int peb2,
                goto out_free;
        }
 
-       seek = peb2 * ui->peb_size;
+       seek = (off_t) peb2 * ui->peb_size;
        if (lseek(fd, seek, SEEK_SET) != seek) {
                sys_errmsg("cannot seek output file");
                goto out_free;