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

Commit 00a309ab authored by Tianjie Xu's avatar Tianjie Xu Committed by android-build-merger
Browse files

Merge "Fix potential OOM in update_verifier"

am: 5443072c

Change-Id: I8bfcd49c0a5f57149d6a87ecfb244273acff3208
parents 5b27cd10 5443072c
Loading
Loading
Loading
Loading
+11 −6
Original line number Original line Diff line number Diff line
@@ -44,6 +44,7 @@
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>


#include <algorithm>
#include <string>
#include <string>
#include <vector>
#include <vector>


@@ -142,18 +143,22 @@ static bool read_blocks(const std::string& partition, const std::string& range_s
      return false;
      return false;
    }
    }


    static constexpr int BLOCKSIZE = 4096;
    static constexpr size_t BLOCKSIZE = 4096;
    if (lseek64(fd.get(), static_cast<off64_t>(range_start) * BLOCKSIZE, SEEK_SET) == -1) {
    if (lseek64(fd.get(), static_cast<off64_t>(range_start) * BLOCKSIZE, SEEK_SET) == -1) {
      PLOG(ERROR) << "lseek to " << range_start << " failed";
      PLOG(ERROR) << "lseek to " << range_start << " failed";
      return false;
      return false;
    }
    }


    size_t size = (range_end - range_start) * BLOCKSIZE;
    size_t remain = (range_end - range_start) * BLOCKSIZE;
    std::vector<uint8_t> buf(size);
    while (remain > 0) {
    if (!android::base::ReadFully(fd.get(), buf.data(), size)) {
      size_t to_read = std::min(remain, 1024 * BLOCKSIZE);
      std::vector<uint8_t> buf(to_read);
      if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) {
        PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end;
        PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end;
        return false;
        return false;
      }
      }
      remain -= to_read;
    }
    blk_count += (range_end - range_start);
    blk_count += (range_end - range_start);
  }
  }