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

Commit 6be8a65c authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[zip] Set all entry times before 1980 to 1980-01-01" into main am: 05a03698 am: cb4bb177

parents e51208de cb4bb177
Loading
Loading
Loading
Loading
+16 −7
Original line number Original line Diff line number Diff line
@@ -363,13 +363,22 @@ void ZipEntry::setModWhen(time_t when)
    struct tm tmResult;
    struct tm tmResult;
    struct tm* ptm = localtime_r(&even, &tmResult);
    struct tm* ptm = localtime_r(&even, &tmResult);


    int year;
    // The earliest valid time for ZIP file entries is 1980-01-01. See:
    year = ptm->tm_year;
    // https://users.cs.jmu.edu/buchhofp/forensics/formats/pkzip.html.
    if (year < 80)
    // Set any time before 1980 to 1980-01-01.
        year = 80;
    if (ptm->tm_year < 80) {

        ptm->tm_year = 80;
    uint16_t zdate = (year - 80) << 9 | (ptm->tm_mon+1) << 5 | ptm->tm_mday;
        ptm->tm_mon = 0;
    uint16_t ztime = ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1;
        ptm->tm_mday = 1;
        ptm->tm_hour = 0;
        ptm->tm_min = 0;
        ptm->tm_sec = 0;
    }

    uint16_t zdate = static_cast<uint16_t>(
        (ptm->tm_year - 80) << 9 | (ptm->tm_mon + 1) << 5 | ptm->tm_mday);
    uint16_t ztime = static_cast<uint16_t>(
        ptm->tm_hour << 11 | ptm->tm_min << 5 | ptm->tm_sec >> 1);


    mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime;
    mCDE.mLastModFileTime = mLFH.mLastModFileTime = ztime;
    mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;
    mCDE.mLastModFileDate = mLFH.mLastModFileDate = zdate;