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

Commit ad0f69c5 authored by Yi-Yo Chiang's avatar Yi-Yo Chiang Committed by Gerrit Code Review
Browse files

Merge "libfiemap: array boundary check for fiemap.fm_extents[]"

parents 3a1ddf55 0f625061
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -514,6 +514,10 @@ static bool IsLastExtent(const fiemap_extent* extent) {
static bool FiemapToExtents(struct fiemap* fiemap, std::vector<struct fiemap_extent>* extents,
                            std::string_view file_path) {
    uint32_t num_extents = fiemap->fm_mapped_extents;
    if (num_extents == 0) {
        LOG(ERROR) << "File " << file_path << " has zero extent";
        return false;
    }
    const struct fiemap_extent* last_extent = &fiemap->fm_extents[num_extents - 1];
    if (!IsLastExtent(last_extent)) {
        LOG(ERROR) << "FIEMAP did not return a final extent for file: " << file_path
+7 −0
Original line number Diff line number Diff line
@@ -258,6 +258,13 @@ TEST_F(FiemapWriterTest, FibmapBlockAddressing) {
    EXPECT_EQ(memcmp(actual.data(), data.data(), data.size()), 0);
}

TEST_F(FiemapWriterTest, CheckEmptyFile) {
    // Can't get any fiemap_extent out of a zero-sized file.
    FiemapUniquePtr fptr = FiemapWriter::Open(testfile, 0);
    EXPECT_EQ(fptr, nullptr);
    EXPECT_EQ(access(testfile.c_str(), F_OK), -1);
}

TEST_F(SplitFiemapTest, Create) {
    auto ptr = SplitFiemap::Create(testfile, 1024 * 768, 1024 * 32);
    ASSERT_NE(ptr, nullptr);