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

Commit ed0546e9 authored by Jin Qian's avatar Jin Qian Committed by Tom Marshall
Browse files

root: Fix an issue when volume length from fs_mgr is negative.

fs_mgr passes negative length as offset for crypt_footer. We need
to compute the actual device size for this case in addition to
when length is zero.

Bug: 68949069
Change-Id: I803955dd9591ad7752cee0dea9b683be8f4fd4ba
(cherry picked from commit cc100088)
parent 8afef8c1
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -347,17 +347,20 @@ int format_volume(const char* volume, const char* directory) {
        }

        int64_t length = 0;
        if (v->length != 0) {
        if (v->length > 0) {
            length = v->length;
        } else if (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0) {
        } else if (v->length < 0 ||
                   (v->key_loc != NULL && strcmp(v->key_loc, "footer") == 0)) {
          android::base::unique_fd fd(open(v->blk_device, O_RDONLY));
          if (fd < 0) {
            PLOG(ERROR) << "format_volume: failed to open " << v->blk_device;
            return -1;
          }
          length = get_file_size(fd.get(), CRYPT_FOOTER_OFFSET);
          length =
              get_file_size(fd.get(), v->length ? -v->length : CRYPT_FOOTER_OFFSET);
          if (length <= 0) {
            LOG(ERROR) << "get_file_size: invalid size " << length << " for " << v->blk_device;
            LOG(ERROR) << "get_file_size: invalid size " << length << " for "
                       << v->blk_device;
            return -1;
          }
        }